Skip to content

Commit

Permalink
conftest: put transaction manager in its own fixture (#16796)
Browse files Browse the repository at this point in the history
Co-authored-by: Dustin Ingram <[email protected]>
Co-authored-by: Mike Fiedler <[email protected]>
  • Loading branch information
3 people authored Oct 2, 2024
1 parent 658f7a2 commit dc5b0e4
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,20 @@ def xmlrpc(self, path, method, *args):


@pytest.fixture
def webtest(app_config_dbsession_from_env, remote_addr):
def tm():
# Create a new transaction manager for dependant test cases
tm = transaction.TransactionManager(explicit=True)
tm.begin()
tm.doom()

yield tm

# Abort the transaction, leaving database in previous state
tm.abort()


@pytest.fixture
def webtest(app_config_dbsession_from_env, remote_addr, tm):
"""
This fixture yields a test app with an alternative Pyramid configuration,
injecting the database session and transaction manager into the app.
Expand All @@ -718,11 +731,6 @@ def webtest(app_config_dbsession_from_env, remote_addr):

app = app_config_dbsession_from_env.make_wsgi_app()

# Create a new transaction manager for dependant test cases
tm = transaction.TransactionManager(explicit=True)
tm.begin()
tm.doom()

with get_db_session_for_app_config(app_config_dbsession_from_env) as _db_session:
# Register the app with the external test environment, telling
# request.db to use this db_session and use the Transaction manager.
Expand All @@ -737,9 +745,6 @@ def webtest(app_config_dbsession_from_env, remote_addr):
)
yield testapp

# Abort the transaction, leaving database in previous state
tm.abort()


class _MockRedis:
"""
Expand Down

0 comments on commit dc5b0e4

Please sign in to comment.