Skip to content

Instantly share code, notes, and snippets.

@sfsekaran
Last active April 28, 2021 07:50
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 sfsekaran/cf232f76fc2c2f682ca45551329b9e77 to your computer and use it in GitHub Desktop.
Save sfsekaran/cf232f76fc2c2f682ca45551329b9e77 to your computer and use it in GitHub Desktop.
Per-Test Database Cleaner (Flask-SQLAlchemy + PyTest)
@pytest.fixture(autouse=True)
def database_cleaner():
db.session.begin()
yield
db.session.rollback()
@rs-sathya
Copy link

Note to self: may have to use session.begin_nested() instead of begin()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment