Open
Conversation
IMO, this makes it significantly easier to maintain tests and write new ones. Testing is still just `python -m pytest` (make sure you're in the virtualenv!)
Instead, create the engine in init, and create connections on each request. It's a teeny bit faster, but the more important part is it makes the fixtures I'm about to create in the next commit easier.
Most of helpers.py was about writing SQL queries in docstrings, and it turns out that that can be all but eliminated by using the ORM. Wasn't able to get mypy type checking to work out yet but I've heard it's possible. IMO this is much cleaner to read, and the minor performance overhead doesn't really matter for us, so the tradeoff is worth it. Also, if we convert all the modules to do this, we can clean up a lot of the database/*.sql scripts (maybe remove them altogether).
This class makes form-parsing much easier. Could certainly be fleshed out and generalized, but that's beyond the scope of this diff.
Note that the ORM setup makes this testing much nicer: - the declarative definition of the schema means that we can easily initialize the test db - the ORM doesn't care about sqlite vs. mariadb differences - ORM object construction > manual SQL INSERT queries
Otherwise how do we get beautiful f-strings? Also, my own PYTHONPATH has /ruddock in it, which is why pytest works for me. That doesn't seem to be the case on Travis. Not sure why it's succeeding for other people.
Closed
Contributor
Author
|
And if anyone can figure out why test_constitution still fails for me, I will be your friend forever |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a re-attempt at #172 .
TL;DR: Using the SqlAlchemy ORM makes testing easier, due to being able to construct the DB in-memory, and also making modifications to the DB before/during tests easier (fewer inline SQL queries).
Ideally we move all the db interactions through SqlAlchemy, but that's a long-term project.
Still some improvements to do, in particular around flask.g (should be loaded when the app-context is pushed, not the request-context).