Last active
December 16, 2015 16:49
-
-
Save drocco007/5466261 to your computer and use it in GitHub Desktop.
pytest fixture for SQLAlchemy tests to wrap each test in its own transaction, which is automatically rolled back when the test completes. Drop into a test module to enable for each test in that module. Or, put it into a package's conftest.py to enable it for every test in that package.
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
@pytest.fixture(autouse=True) | |
def close_transaction(request): | |
session.begin(subtransactions=True) | |
request.addfinalizer(session.rollback) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment