Skip to content

Commit 973900f

Browse files
committed
🧪 Improve test consistency
Ensures all tests have same setup for Run initialisation, also adds flag for changing retention period
1 parent c4f2810 commit 973900f

File tree

3 files changed

+224
-122
lines changed

3 files changed

+224
-122
lines changed

‎simvue/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ def delete_folder(
440440
return None
441441
else:
442442
raise ObjectNotFoundError(
443-
f"Deletion of folder '{folder_path}' failed, folder does not exist."
443+
name=folder_path,
444+
obj_type="folder",
444445
)
445446
_response = Folder(identifier=folder_id).delete(
446447
delete_runs=remove_runs, recursive=recursive, runs_only=False

‎tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
def pytest_addoption(parser):
2929
parser.addoption("--debug-simvue", action="store_true", default=False)
30+
parser.addoption("--retention-period", default="2 mins")
3031

3132

3233
class CountingLogHandler(logging.Handler):
@@ -119,11 +120,13 @@ def speedy_heartbeat(monkeypatch: monkeypatch.MonkeyPatch) -> None:
119120

120121

121122
@pytest.fixture(autouse=True)
122-
def setup_logging(pytestconfig) -> CountingLogHandler:
123+
def setup_logging(pytestconfig, monkeypatch) -> CountingLogHandler:
123124
logging.basicConfig(level=logging.WARNING)
124125
handler = CountingLogHandler()
125126
logging.getLogger("simvue").setLevel(logging.DEBUG if pytestconfig.getoption("debug_simvue") else logging.WARNING)
126127
logging.getLogger("simvue").addHandler(handler)
128+
if (_retention := pytestconfig.getoption("retention_period")):
129+
monkeypatch.setenv("SIMVUE_TESTING_RETENTION_PERIOD", _retention)
127130
return handler
128131

129132

@@ -159,6 +162,11 @@ def testing_exit(status: int) -> None:
159162
monkeypatch.setenv("SIMVUE_OFFLINE_DIRECTORY", temp_d)
160163
with sv_run.Run("offline") as run:
161164
yield run, setup_test_run(run, True, request)
165+
with contextlib.suppress(ObjectNotFoundError):
166+
sv_api_obj.Folder(identifier=run._folder.id).delete(recursive=True, delete_runs=True, runs_only=False)
167+
for alert_id in _test_run_data.get("alert_ids", []):
168+
with contextlib.suppress(ObjectNotFoundError):
169+
sv_api_obj.Alert(identifier=alert_id).delete()
162170
clear_out_files()
163171

164172

@@ -223,7 +231,7 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
223231
tags=TEST_DATA["tags"],
224232
folder=TEST_DATA["folder"],
225233
visibility="tenant" if os.environ.get("CI") else None,
226-
retention_period="1 hour",
234+
retention_period=os.environ.get("SIMVUE_TESTING_RETENTION_PERIOD", "2 mins"),
227235
timeout=60,
228236
no_color=True,
229237
running=not created_only

0 commit comments

Comments
 (0)