Created
October 15, 2014 14:49
-
-
Save ScottSturdivant/1e4617a52b48c27d335c to your computer and use it in GitHub Desktop.
sqlalchemy test isolation
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
@pytest.fixture(scope='session') | |
def db(app, request): | |
_db.create_all() | |
def teardown(): | |
_db.session.remove() | |
_db.drop_all() | |
request.addfinalizer(teardown) | |
return _db | |
@pytest.fixture(scope='function', autouse=True) | |
def transact(request, db, monkeypatch): | |
request.addfinalizer(db.session.remove) | |
monkeypatch.setattr(db.session, 'commit', db.session.flush) | |
monkeypatch.setattr(db.session, 'remove', lambda: None) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment