From 29a8002a5026fee3ec78836b8cf8b518776dd623 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Fri, 26 Jun 2026 10:47:36 +0100 Subject: [PATCH 1/2] Fix issue where test.db was created in project root --- tests/conftest.py | 2 +- tests/integration/test_pacs_storage_upload.py | 8 +++---- tests/scripts/test_database.py | 23 +++++++++---------- .../services/mwl/test_create_worklist_item.py | 6 ++--- .../mwl/test_update_worklist_item_status.py | 4 ++-- tests/services/test_storage.py | 8 +++---- 6 files changed, 25 insertions(+), 26 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3e878e88..ebdaa0e6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,7 +66,7 @@ def mock_azure_credential(): @pytest.fixture def tmp_dir(): - return f"{Path(__file__).parent}/tmp" + return Path(__file__).parent / "tmp" @pytest.fixture(autouse=True) diff --git a/tests/integration/test_pacs_storage_upload.py b/tests/integration/test_pacs_storage_upload.py index e578407c..2e530c63 100644 --- a/tests/integration/test_pacs_storage_upload.py +++ b/tests/integration/test_pacs_storage_upload.py @@ -4,15 +4,15 @@ @pytest.fixture -def mwl_storage(tmp_path): +def mwl_storage(tmp_dir): """Create MWLStorage instance with temp database.""" - return MWLStorage(db_path=f"{tmp_path}/worklist.db") + return MWLStorage(db_path=f"{tmp_dir}/worklist.db") @pytest.fixture -def pacs_storage(tmp_path): +def pacs_storage(tmp_dir): """Create PACSStorage instance with temp database.""" - return PACSStorage(db_path=f"{tmp_path}/pacs.db", storage_root=str(tmp_path / "storage")) + return PACSStorage(db_path=f"{tmp_dir}/pacs.db", storage_root=f"{tmp_dir}/storage") class TestPACSStorageUpload: diff --git a/tests/scripts/test_database.py b/tests/scripts/test_database.py index 80d87f59..8831c554 100644 --- a/tests/scripts/test_database.py +++ b/tests/scripts/test_database.py @@ -12,8 +12,13 @@ @pytest.fixture -def sqlite_db(tmp_path): - db_path = tmp_path / "test.db" +def backup_dir(tmp_dir): + return tmp_dir / "backups" + + +@pytest.fixture +def sqlite_db(tmp_dir): + db_path = tmp_dir / "test.db" conn = sqlite3.connect(db_path) @@ -45,12 +50,11 @@ def row_count(db_path, table): def test_backup_and_reset_creates_backup( - tmp_path, + backup_dir, sqlite_db, monkeypatch, ): """Backup database creates backup.""" - backup_dir = tmp_path / "backups" monkeypatch.setenv("DB_PATH", str(sqlite_db)) monkeypatch.setenv("TABLE_NAME", "stored_instances") monkeypatch.setenv("BACKUP_PATH", str(backup_dir)) @@ -71,12 +75,11 @@ def test_backup_and_reset_creates_backup( def test_rotation_keeps_five_backups( - tmp_path, + backup_dir, sqlite_db, monkeypatch, ): """Only 5 database backups are kept and older ones are deleted.""" - backup_dir = tmp_path / "backups" monkeypatch.setenv("DB_PATH", str(sqlite_db)) monkeypatch.setenv("TABLE_NAME", "stored_instances") monkeypatch.setenv("BACKUP_PATH", str(backup_dir)) @@ -110,13 +113,11 @@ def test_rotation_keeps_five_backups( def test_newest_backup_is_backup_zero( - tmp_path, + backup_dir, sqlite_db, monkeypatch, ): """Newest backup is always backup.0.""" - backup_dir = tmp_path / "backups" - monkeypatch.setenv("DB_PATH", str(sqlite_db)) monkeypatch.setenv("TABLE_NAME", "stored_instances") monkeypatch.setenv("BACKUP_PATH", str(backup_dir)) @@ -141,13 +142,11 @@ def test_newest_backup_is_backup_zero( def test_invalid_table_name_is_ignored( - tmp_path, + backup_dir, sqlite_db, monkeypatch, ): """Invalid table name is ignored.""" - backup_dir = tmp_path / "backups" - monkeypatch.setenv("DB_PATH", str(sqlite_db)) monkeypatch.setenv("TABLE_NAME", "users") monkeypatch.setenv("BACKUP_PATH", str(backup_dir)) diff --git a/tests/services/mwl/test_create_worklist_item.py b/tests/services/mwl/test_create_worklist_item.py index bbd5f34b..981718f8 100644 --- a/tests/services/mwl/test_create_worklist_item.py +++ b/tests/services/mwl/test_create_worklist_item.py @@ -8,12 +8,12 @@ class TestCreateWorklistItem: @pytest.fixture - def db_file(tmp_path): - return f"{tmp_path}/test.db" + def db_file(self, tmp_dir): + return tmp_dir / "test.db" @pytest.fixture def mwl_storage(self, db_file): - return MWLStorage(str(db_file)) + return MWLStorage(db_file) def test_call_success(self, mwl_storage, listener_payload): """Create worklist item: Call success.""" diff --git a/tests/services/mwl/test_update_worklist_item_status.py b/tests/services/mwl/test_update_worklist_item_status.py index 8f17340d..01b70bb3 100644 --- a/tests/services/mwl/test_update_worklist_item_status.py +++ b/tests/services/mwl/test_update_worklist_item_status.py @@ -28,8 +28,8 @@ def status_update_payload(self): } @pytest.fixture - def db_file(self, tmp_path) -> str: - return f"{tmp_path}/test.db" + def db_file(self, tmp_dir) -> str: + return tmp_dir / "test.db" @pytest.fixture def mwl_storage(self, db_file: str): diff --git a/tests/services/test_storage.py b/tests/services/test_storage.py index 210ac8d0..4f6e92d2 100644 --- a/tests/services/test_storage.py +++ b/tests/services/test_storage.py @@ -16,13 +16,13 @@ @pytest.fixture -def db_file(tmp_path): - return tmp_path / "test.db" +def db_file(tmp_dir): + return tmp_dir / "test.db" @pytest.fixture -def pacs_storage(db_file, tmp_path): - storage = PACSStorage(str(db_file), str(tmp_path)) +def pacs_storage(db_file, tmp_dir): + storage = PACSStorage(str(db_file), str(tmp_dir)) return storage From db8a01a8fc8122d5729f1e7a322b0e40a5c7d646 Mon Sep 17 00:00:00 2001 From: Steve Laing Date: Fri, 26 Jun 2026 11:05:25 +0100 Subject: [PATCH 2/2] Make readable test names play nicely with neotest Pytest uses :: as a delimiter in tests and apparently the neotest plugin relies on this for _stuff_. --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index ebdaa0e6..6f311737 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,6 +15,8 @@ sys.path.append(f"{Path(__file__).parent.parent}/src") +READABLE_TEST_OUTPUT = not any("neotest" in arg for arg in sys.argv) + def pytest_html_report_title(report): report.title = "Rubie Gateway Tests" @@ -49,7 +51,7 @@ def pytest_runtest_makereport(item, call): report = outcome.get_result() readable_name = _readable_test_name(item) - if readable_name: + if readable_name and READABLE_TEST_OUTPUT: report.nodeid = readable_name