Open heartsucker opened 6 years ago
Note, this definitely is fixed with:
# manually refresh the object between requests
db_object = Journalist.query.get(db_object.id)
and may be fixed by changing the fixtures to this:
# conftest.py
@pytest.fixture(scope='function')
def journalist_app(config):
app = create_journalist_app(config)
with app.app_context():
db.create_all()
# note that we yield the app instead of return,
# and we do it *inside* the pushed app context
yield app
Though this may end up with cases where we've double pushed a context, and I have no idea what would happen there.
Bug
Description
During tests if we reuse a database object after a view function that calls
db.session.commit
, we may end up running assertions against a stale object.Example
Expected Behavior
Our tests accurately check when there were or were not alterations in the database.
Actual Behavior
They do not.
Comments
We should requery the DB for the object between requests. Calling
db.session.refresh(foo)
breaks and yells because thesession
attached to the initial object has popped.