From aec3531127653b981e00ae7e0b009e62835cc372 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Wed, 21 Jul 2021 12:49:32 +1000 Subject: [PATCH] Cleanup test helper data before and after running --- backend/tests/conftest.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index 28414553..3c620e6b 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -12,6 +12,21 @@ import os global app + +def cleanup(datastore_path): + # Unlink test output files + files = ['output.txt', + 'url-watches.json', + 'notification.txt', + 'count.txt', + 'endpoint-content.txt'] + for file in files: + try: + os.unlink("{}/{}".format(datastore_path, file)) + x = 1 + except FileNotFoundError: + pass + @pytest.fixture(scope='session') def app(request): """Create application for the tests.""" @@ -25,15 +40,7 @@ def app(request): # Enable a BASE_URL for notifications to work (so we can look for diff/ etc URLs) os.environ["BASE_URL"] = "http://mysite.com/" - # Unlink test output files - files = ['test-datastore/output.txt', - "{}/url-watches.json".format(datastore_path), - 'test-datastore/notification.txt'] - for file in files: - try: - os.unlink(file) - except FileNotFoundError: - pass + cleanup(datastore_path) app_config = {'datastore_path': datastore_path} datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], include_default_watches=False) @@ -43,13 +50,8 @@ def app(request): def teardown(): datastore.stop_thread = True app.config.exit.set() - for fname in ["url-watches.json", "count.txt", "output.txt"]: - try: - os.unlink("{}/{}".format(datastore_path, fname)) - except FileNotFoundError: - # This is fine in the case of a failure. - pass - + cleanup(datastore_path) + request.addfinalizer(teardown) yield app