Skip to content

Commit 978cd1f

Browse files
committed
Fix os._exit in tests
1 parent 2d375d4 commit 978cd1f

File tree

3 files changed

+111
-76
lines changed

3 files changed

+111
-76
lines changed

tests/conftest.py

Lines changed: 11 additions & 2 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()

tests/functional/test_client.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,10 +384,7 @@ def test_alert_deletion() -> None:
384384

385385

386386
@pytest.mark.client
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())
387+
def test_abort_run(create_plain_run: tuple[sv_run.Run, dict]) -> None:
391388
run, run_data = create_plain_run
392389
_uuid = f"{uuid.uuid4()}".split("-")[0]
393390
run.update_tags([f"delete_me_{_uuid}"])

0 commit comments

Comments
 (0)