Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conftest: put transaction manager in its own fixture #16796

Merged
merged 6 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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