From dc5b0e4820de5dddbc4d9467cda8398876d686b4 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Wed, 2 Oct 2024 11:27:00 -0400 Subject: [PATCH] conftest: put transaction manager in its own fixture (#16796) Co-authored-by: Dustin Ingram Co-authored-by: Mike Fiedler --- tests/conftest.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b66e02672934..cc0847bdc8b0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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. @@ -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. @@ -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: """