summaryrefslogtreecommitdiff
path: root/yoyo
diff options
context:
space:
mode:
authorOlly Cope <olly@ollycope.com>2022-10-03 10:37:22 +0000
committerOlly Cope <olly@ollycope.com>2022-10-03 10:37:22 +0000
commit72d73a43f0b5c4662cda74e4a4c02d63234e9633 (patch)
tree8e5bc571f66addbaf9469ae5d54231f6b4f3df0a /yoyo
parent3e81c59248e1a7baf30d1118ae3bcbf5625af970 (diff)
downloadyoyo-72d73a43f0b5c4662cda74e4a4c02d63234e9633.tar.gz
tests: drop tables created by tests that access a backend via a fixture
I was seeing spurious test failures due to lack of teardown code. This is an unobtrusive fix for the problem.
Diffstat (limited to 'yoyo')
-rw-r--r--yoyo/tests/conftest.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/yoyo/tests/conftest.py b/yoyo/tests/conftest.py
index ca31425..f92e59e 100644
--- a/yoyo/tests/conftest.py
+++ b/yoyo/tests/conftest.py
@@ -25,7 +25,8 @@ def _backend(dburi):
yield backend
finally:
backend.rollback()
- drop_yoyo_tables(backend)
+ with backend.transaction():
+ drop_all_tables(backend)
@pytest.fixture(params=get_test_dburis())
@@ -46,7 +47,14 @@ def dburi(request):
try:
yield request.param
finally:
- drop_yoyo_tables(get_backend(request.param))
+ backend = get_backend(request.param)
+ with backend.transaction():
+ drop_all_tables(backend)
+
+
+def drop_all_tables(backend):
+ for t in backend.list_tables():
+ backend.execute(f"DROP TABLE {backend.quote_identifier(t)}")
def drop_yoyo_tables(backend):