Skip to content

Commit 2d375d4

Browse files
committed
Correct abort test
1 parent cfb48a0 commit 2d375d4

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

tests/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,24 @@ def create_run_object() -> sv_api_obj.Run:
114114

115115
def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.FixtureRequest, created_only: bool=False):
116116
fix_use_id: str = str(uuid.uuid4()).split('-', 1)[0]
117+
_test_name: str = request.node.name.replace("[", "_").replace("]", "")
117118
TEST_DATA = {
118119
"event_contains": "sent event",
119120
"metadata": {
120121
"test_engine": "pytest",
121-
"test_identifier": fix_use_id
122+
"test_identifier": f"{_test_name}_{fix_use_id}"
122123
},
123124
"folder": f"/simvue_unit_testing/{fix_use_id}",
124-
"tags": ["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "")]
125+
"tags": ["simvue_client_unit_tests", _test_name]
125126
}
126127

127128
if os.environ.get("CI"):
128129
TEST_DATA["tags"].append("ci")
129130

130131
run.config(suppress_errors=False)
132+
run._heartbeat_interval = 1
131133
run.init(
132-
name=f"test_run_{TEST_DATA['metadata']['test_identifier']}_{uuid.uuid4()}",
134+
name=TEST_DATA['metadata']['test_identifier'],
133135
tags=TEST_DATA["tags"],
134136
folder=TEST_DATA["folder"],
135137
visibility="tenant" if os.environ.get("CI") else None,

tests/functional/test_client.py

Lines changed: 9 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,17 @@ 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], mocker: pytest_mock.MockerFixture) -> None:
388+
def alt_exit():
389+
raise SystemExit
390+
mocker.patch("os._exit", lambda *_, **__: alt_exit())
391+
run, run_data = create_plain_run
387392
_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()
393+
run.update_tags([f"delete_me_{_uuid}"])
393394
time.sleep(1)
394395
_client = svc.Client()
395-
_client.abort_run(_run.id, reason="Test abort")
396+
_client.abort_run(run.id, reason="Test abort")
396397
time.sleep(1)
397-
assert _run.abort_trigger
398-
_run.delete()
399-
_folder.delete(recursive=True, delete_runs=True, runs_only=False)
398+
assert run._status == "terminated"
400399

401400

0 commit comments

Comments
 (0)