Skip to content

Commit e123943

Browse files
authored
Merge pull request #150 from NHSDigital/fix-test-suite-tmp-dir-issue
Fix test suite tmp dir issue
2 parents 1bf2892 + db8a01a commit e123943

6 files changed

Lines changed: 28 additions & 27 deletions

File tree

tests/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
sys.path.append(f"{Path(__file__).parent.parent}/src")
1717

18+
READABLE_TEST_OUTPUT = not any("neotest" in arg for arg in sys.argv)
19+
1820

1921
def pytest_html_report_title(report):
2022
report.title = "Rubie Gateway Tests"
@@ -49,7 +51,7 @@ def pytest_runtest_makereport(item, call):
4951
report = outcome.get_result()
5052

5153
readable_name = _readable_test_name(item)
52-
if readable_name:
54+
if readable_name and READABLE_TEST_OUTPUT:
5355
report.nodeid = readable_name
5456

5557

@@ -66,7 +68,7 @@ def mock_azure_credential():
6668

6769
@pytest.fixture
6870
def tmp_dir():
69-
return f"{Path(__file__).parent}/tmp"
71+
return Path(__file__).parent / "tmp"
7072

7173

7274
@pytest.fixture(autouse=True)

tests/integration/test_pacs_storage_upload.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55

66
@pytest.fixture
7-
def mwl_storage(tmp_path):
7+
def mwl_storage(tmp_dir):
88
"""Create MWLStorage instance with temp database."""
9-
return MWLStorage(db_path=f"{tmp_path}/worklist.db")
9+
return MWLStorage(db_path=f"{tmp_dir}/worklist.db")
1010

1111

1212
@pytest.fixture
13-
def pacs_storage(tmp_path):
13+
def pacs_storage(tmp_dir):
1414
"""Create PACSStorage instance with temp database."""
15-
return PACSStorage(db_path=f"{tmp_path}/pacs.db", storage_root=str(tmp_path / "storage"))
15+
return PACSStorage(db_path=f"{tmp_dir}/pacs.db", storage_root=f"{tmp_dir}/storage")
1616

1717

1818
class TestPACSStorageUpload:

tests/scripts/test_database.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212

1313

1414
@pytest.fixture
15-
def sqlite_db(tmp_path):
16-
db_path = tmp_path / "test.db"
15+
def backup_dir(tmp_dir):
16+
return tmp_dir / "backups"
17+
18+
19+
@pytest.fixture
20+
def sqlite_db(tmp_dir):
21+
db_path = tmp_dir / "test.db"
1722

1823
conn = sqlite3.connect(db_path)
1924

@@ -45,12 +50,11 @@ def row_count(db_path, table):
4550

4651

4752
def test_backup_and_reset_creates_backup(
48-
tmp_path,
53+
backup_dir,
4954
sqlite_db,
5055
monkeypatch,
5156
):
5257
"""Backup database creates backup."""
53-
backup_dir = tmp_path / "backups"
5458
monkeypatch.setenv("DB_PATH", str(sqlite_db))
5559
monkeypatch.setenv("TABLE_NAME", "stored_instances")
5660
monkeypatch.setenv("BACKUP_PATH", str(backup_dir))
@@ -71,12 +75,11 @@ def test_backup_and_reset_creates_backup(
7175

7276

7377
def test_rotation_keeps_five_backups(
74-
tmp_path,
78+
backup_dir,
7579
sqlite_db,
7680
monkeypatch,
7781
):
7882
"""Only 5 database backups are kept and older ones are deleted."""
79-
backup_dir = tmp_path / "backups"
8083
monkeypatch.setenv("DB_PATH", str(sqlite_db))
8184
monkeypatch.setenv("TABLE_NAME", "stored_instances")
8285
monkeypatch.setenv("BACKUP_PATH", str(backup_dir))
@@ -110,13 +113,11 @@ def test_rotation_keeps_five_backups(
110113

111114

112115
def test_newest_backup_is_backup_zero(
113-
tmp_path,
116+
backup_dir,
114117
sqlite_db,
115118
monkeypatch,
116119
):
117120
"""Newest backup is always backup.0."""
118-
backup_dir = tmp_path / "backups"
119-
120121
monkeypatch.setenv("DB_PATH", str(sqlite_db))
121122
monkeypatch.setenv("TABLE_NAME", "stored_instances")
122123
monkeypatch.setenv("BACKUP_PATH", str(backup_dir))
@@ -141,13 +142,11 @@ def test_newest_backup_is_backup_zero(
141142

142143

143144
def test_invalid_table_name_is_ignored(
144-
tmp_path,
145+
backup_dir,
145146
sqlite_db,
146147
monkeypatch,
147148
):
148149
"""Invalid table name is ignored."""
149-
backup_dir = tmp_path / "backups"
150-
151150
monkeypatch.setenv("DB_PATH", str(sqlite_db))
152151
monkeypatch.setenv("TABLE_NAME", "users")
153152
monkeypatch.setenv("BACKUP_PATH", str(backup_dir))

tests/services/mwl/test_create_worklist_item.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
class TestCreateWorklistItem:
1010
@pytest.fixture
11-
def db_file(tmp_path):
12-
return f"{tmp_path}/test.db"
11+
def db_file(self, tmp_dir):
12+
return tmp_dir / "test.db"
1313

1414
@pytest.fixture
1515
def mwl_storage(self, db_file):
16-
return MWLStorage(str(db_file))
16+
return MWLStorage(db_file)
1717

1818
def test_call_success(self, mwl_storage, listener_payload):
1919
"""Create worklist item: Call success."""

tests/services/mwl/test_update_worklist_item_status.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def status_update_payload(self):
2828
}
2929

3030
@pytest.fixture
31-
def db_file(self, tmp_path) -> str:
32-
return f"{tmp_path}/test.db"
31+
def db_file(self, tmp_dir) -> str:
32+
return tmp_dir / "test.db"
3333

3434
@pytest.fixture
3535
def mwl_storage(self, db_file: str):

tests/services/test_storage.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717

1818
@pytest.fixture
19-
def db_file(tmp_path):
20-
return tmp_path / "test.db"
19+
def db_file(tmp_dir):
20+
return tmp_dir / "test.db"
2121

2222

2323
@pytest.fixture
24-
def pacs_storage(db_file, tmp_path):
25-
storage = PACSStorage(str(db_file), str(tmp_path))
24+
def pacs_storage(db_file, tmp_dir):
25+
storage = PACSStorage(str(db_file), str(tmp_dir))
2626
return storage
2727

2828

0 commit comments

Comments
 (0)