Skip to content

Instantly share code, notes, and snippets.

@jaysonsantos
Created October 27, 2017 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaysonsantos/7025c97ccb1e831be8523b4af3ebf788 to your computer and use it in GitHub Desktop.
Save jaysonsantos/7025c97ccb1e831be8523b4af3ebf788 to your computer and use it in GitHub Desktop.
sqlalchemy + pytest patch session to avoid commits on tests
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