|
27 | 27 |
|
28 | 28 | def pytest_addoption(parser):
|
29 | 29 | parser.addoption("--debug-simvue", action="store_true", default=False)
|
| 30 | + parser.addoption("--retention-period", default="2 mins") |
30 | 31 |
|
31 | 32 |
|
32 | 33 | class CountingLogHandler(logging.Handler):
|
@@ -119,11 +120,13 @@ def speedy_heartbeat(monkeypatch: monkeypatch.MonkeyPatch) -> None:
|
119 | 120 |
|
120 | 121 |
|
121 | 122 | @pytest.fixture(autouse=True)
|
122 |
| -def setup_logging(pytestconfig) -> CountingLogHandler: |
| 123 | +def setup_logging(pytestconfig, monkeypatch) -> CountingLogHandler: |
123 | 124 | logging.basicConfig(level=logging.WARNING)
|
124 | 125 | handler = CountingLogHandler()
|
125 | 126 | logging.getLogger("simvue").setLevel(logging.DEBUG if pytestconfig.getoption("debug_simvue") else logging.WARNING)
|
126 | 127 | logging.getLogger("simvue").addHandler(handler)
|
| 128 | + if (_retention := pytestconfig.getoption("retention_period")): |
| 129 | + monkeypatch.setenv("SIMVUE_TESTING_RETENTION_PERIOD", _retention) |
127 | 130 | return handler
|
128 | 131 |
|
129 | 132 |
|
@@ -159,6 +162,11 @@ def testing_exit(status: int) -> None:
|
159 | 162 | monkeypatch.setenv("SIMVUE_OFFLINE_DIRECTORY", temp_d)
|
160 | 163 | with sv_run.Run("offline") as run:
|
161 | 164 | 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() |
162 | 170 | clear_out_files()
|
163 | 171 |
|
164 | 172 |
|
@@ -223,7 +231,7 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
|
223 | 231 | tags=TEST_DATA["tags"],
|
224 | 232 | folder=TEST_DATA["folder"],
|
225 | 233 | 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"), |
227 | 235 | timeout=60,
|
228 | 236 | no_color=True,
|
229 | 237 | running=not created_only
|
|
0 commit comments