Skip to content

Commit 00ede27

Browse files
authored
Merge pull request #755 from simvue-io/hotfix/fix-abort-test
Fix abort test
2 parents 6c5bfce + 978cd1f commit 00ede27

File tree

3 files changed

+121
-85
lines changed

3 files changed

+121
-85
lines changed

tests/conftest.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ def create_test_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict],
7171

7272
@pytest.fixture
7373
def create_test_run_offline(mocker: pytest_mock.MockerFixture, request, monkeypatch: pytest.MonkeyPatch) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
74+
def testing_exit(status: int) -> None:
75+
raise SystemExit(status)
76+
mocker.patch("os._exit", testing_exit)
7477
with tempfile.TemporaryDirectory() as temp_d:
7578
monkeypatch.setenv("SIMVUE_OFFLINE_DIRECTORY", temp_d)
7679
with sv_run.Run("offline") as run:
@@ -79,7 +82,10 @@ def create_test_run_offline(mocker: pytest_mock.MockerFixture, request, monkeypa
7982

8083

8184
@pytest.fixture
82-
def create_plain_run(request) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
85+
def create_plain_run(request, mocker: pytest_mock.MockFixture) -> typing.Generator[typing.Tuple[sv_run.Run, dict], None, None]:
86+
def testing_exit(status: int) -> None:
87+
raise SystemExit(status)
88+
mocker.patch("os._exit", testing_exit)
8389
with sv_run.Run() as run:
8490
yield run, setup_test_run(run, False, request)
8591
clear_out_files()
@@ -102,7 +108,10 @@ def create_plain_run_offline(mocker: pytest_mock.MockerFixture, request, monkeyp
102108

103109

104110
@pytest.fixture
105-
def create_run_object() -> sv_api_obj.Run:
111+
def create_run_object(mocker: pytest_mock.MockFixture) -> sv_api_obj.Run:
112+
def testing_exit(status: int) -> None:
113+
raise SystemExit(status)
114+
mocker.patch("os._exit", testing_exit)
106115
_fix_use_id: str = str(uuid.uuid4()).split('-', 1)[0]
107116
_folder = sv_api_obj.Folder.new(path=f"/simvue_unit_testing/{_fix_use_id}")
108117
_folder.commit()
@@ -114,22 +123,24 @@ def create_run_object() -> sv_api_obj.Run:
114123

115124
def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.FixtureRequest, created_only: bool=False):
116125
fix_use_id: str = str(uuid.uuid4()).split('-', 1)[0]
126+
_test_name: str = request.node.name.replace("[", "_").replace("]", "")
117127
TEST_DATA = {
118128
"event_contains": "sent event",
119129
"metadata": {
120130
"test_engine": "pytest",
121-
"test_identifier": fix_use_id
131+
"test_identifier": f"{_test_name}_{fix_use_id}"
122132
},
123133
"folder": f"/simvue_unit_testing/{fix_use_id}",
124-
"tags": ["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "")]
134+
"tags": ["simvue_client_unit_tests", _test_name]
125135
}
126136

127137
if os.environ.get("CI"):
128138
TEST_DATA["tags"].append("ci")
129139

130140
run.config(suppress_errors=False)
141+
run._heartbeat_interval = 1
131142
run.init(
132-
name=f"test_run_{TEST_DATA['metadata']['test_identifier']}_{uuid.uuid4()}",
143+
name=TEST_DATA['metadata']['test_identifier'],
133144
tags=TEST_DATA["tags"],
134145
folder=TEST_DATA["folder"],
135146
visibility="tenant" if os.environ.get("CI") else None,

tests/functional/test_client.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import glob
88
import pathlib
99
import time
10+
import pytest_mock
1011
import tempfile
1112
import simvue.client as svc
1213
from simvue.exception import ObjectNotFoundError
@@ -383,19 +384,14 @@ def test_alert_deletion() -> None:
383384

384385

385386
@pytest.mark.client
386-
def test_abort_run() -> None:
387+
def test_abort_run(create_plain_run: tuple[sv_run.Run, dict]) -> None:
388+
run, run_data = create_plain_run
387389
_uuid = f"{uuid.uuid4()}".split("-")[0]
388-
_folder = sv_api_obj.Folder.new(path=f"/simvue_unit_testing/{_uuid}")
389-
_run = sv_api_obj.Run.new(folder=f"/simvue_unit_testing/{_uuid}")
390-
_run.status = "running"
391-
_folder.commit()
392-
_run.commit()
390+
run.update_tags([f"delete_me_{_uuid}"])
393391
time.sleep(1)
394392
_client = svc.Client()
395-
_client.abort_run(_run.id, reason="Test abort")
393+
_client.abort_run(run.id, reason="Test abort")
396394
time.sleep(1)
397-
assert _run.abort_trigger
398-
_run.delete()
399-
_folder.delete(recursive=True, delete_runs=True, runs_only=False)
395+
assert run._status == "terminated"
400396

401397

0 commit comments

Comments
 (0)