Created
October 27, 2017 17:51
-
-
Save jaysonsantos/7025c97ccb1e831be8523b4af3ebf788 to your computer and use it in GitHub Desktop.
sqlalchemy + pytest patch session to avoid commits on tests
This file contains 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
import pytest | |
@pytest.yield_fixture(scope='session') | |
def patch_session(): | |
def commit(): | |
"""Flush and expire caches.""" | |
db.session.flush() | |
db.session.expire_all() | |
old_commit = db.session.commit | |
db.session.commit = commit | |
yield | |
db.session.commit = old_commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment