Skip to content

Commit 97f57c5

Browse files
committed
🧪 Various test fixes based on Windows issues
1 parent 7753898 commit 97f57c5

10 files changed

Lines changed: 78 additions & 61 deletions

‎simvue/api/objects/base.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ def _post(self, is_json: bool = True, **kwargs) -> dict[str, typing.Any]:
563563
if _id := _json_response.get("id"):
564564
self._logger.debug("'%s' created successfully", _id)
565565
self._identifier = _id
566+
else:
567+
_detail = _json_response.get("detail", "")
568+
raise RuntimeError(f"Expected new ID for {self._label} but none found: {_detail}.")
566569

567570
return _json_response
568571

‎tests/conftest.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tempfile
88
import os
99
import json
10+
import platform
1011
import pathlib
1112
import logging
1213
import requests
@@ -43,8 +44,8 @@ def emit(self, record):
4344

4445

4546
def clear_out_files() -> None:
46-
out_files = list(pathlib.Path.cwd().glob("test_*.out"))
47-
out_files += list(pathlib.Path.cwd().glob("test_*.err"))
47+
out_files = list(pathlib.Path.cwd().glob(f"test_*_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.out"))
48+
out_files += list(pathlib.Path.cwd().glob(f"test_*_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.err"))
4849

4950
for file_obj in out_files:
5051
file_obj.unlink()
@@ -213,7 +214,7 @@ def setup_test_run(run: sv_run.Run, create_objects: bool, request: pytest.Fixtur
213214
"test_identifier": f"{_test_name}_{fix_use_id}"
214215
},
215216
"folder": f"/simvue_unit_testing/{fix_use_id}",
216-
"tags": ["simvue_client_unit_tests", _test_name]
217+
"tags": ["simvue_client_unit_tests", _test_name, f"{platform.system()}"]
217218
}
218219

219220
if os.environ.get("CI"):

‎tests/functional/test_client.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import platform
23
import uuid
34
import random
45
import os.path
@@ -39,7 +40,7 @@ def test_get_alerts(
3940
run.init(
4041
"test_get_alerts",
4142
folder=f"/simvue_unit_testing/{unique_id}",
42-
tags=["test_get_alerts"],
43+
tags=["test_get_alerts", platform.system()],
4344
retention_period="2 mins",
4445
)
4546
run_id = run.id
@@ -249,8 +250,11 @@ def test_get_runs(
249250
output_format=output_format,
250251
count_limit=10,
251252
sort_by_columns=sorting,
252-
timing_info=True,
253-
system_info=True,
253+
timing_info=timing_info,
254+
system_info=system_info,
255+
metrics=metrics,
256+
metadata=metadata,
257+
alerts=alerts,
254258
attributes=attributes
255259
)
256260

@@ -325,7 +329,7 @@ def test_run_deletion() -> None:
325329
run.init(
326330
name="test_run_deletion",
327331
folder="/simvue_unit_testing",
328-
tags=["test_run_deletion"],
332+
tags=["test_run_deletion", platform.system()],
329333
retention_period="1 min",
330334
)
331335
run.log_metrics({"x": 2})
@@ -344,7 +348,7 @@ def test_runs_deletion() -> None:
344348
run.init(
345349
name="test_runs_deletion",
346350
folder="/simvue_unit_testing/runs_batch",
347-
tags=["test_runs_deletion"],
351+
tags=["test_runs_deletion", platform.system()],
348352
retention_period="1 min",
349353
)
350354
run.log_metrics({"x": i})
@@ -359,7 +363,7 @@ def test_runs_deletion() -> None:
359363
@pytest.mark.object_retrieval
360364
def test_get_tags() -> None:
361365
_uuid = f"{uuid.uuid4()}".split("-")[0]
362-
tags = ["simvue_unit_testing", "test_get_tags", "testing", _uuid]
366+
tags = ["simvue_unit_testing", "test_get_tags", "testing", _uuid, platform.system()]
363367

364368
with sv_run.Run() as run:
365369
run.init(
@@ -390,7 +394,7 @@ def test_folder_deletion() -> None:
390394
run.init(
391395
name="test_folder_deletion",
392396
folder=f"/simvue_unit_testing/{_temp_folder_id}",
393-
tags=["test_folder_deletion"],
397+
tags=["test_folder_deletion", platform.system()],
394398
retention_period="1 min",
395399
)
396400
run.close()
@@ -418,7 +422,7 @@ def test_run_folder_metadata_find() -> None:
418422
with sv_run.Run() as run:
419423
run.init(
420424
"test_run_folder_metadata_find",
421-
tags=["test_run_folder_metadata_find", "testing"],
425+
tags=["test_run_folder_metadata_find", "testing", platform.system()],
422426
folder=(_folder := f"/simvue_unit_testing/{_uuid}"),
423427
retention_period="2 mins"
424428
)
@@ -438,7 +442,7 @@ def test_tag_deletion() -> None:
438442
run.init(
439443
name="test_folder_deletion",
440444
folder=f"/simvue_unit_testing/{unique_id}",
441-
tags=["test_tag_deletion"],
445+
tags=["test_tag_deletion", platform.system()],
442446
retention_period="1 min",
443447
)
444448
run.update_tags([(tag_str := f"delete_me_{unique_id}")])

‎tests/functional/test_executor.py‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import contextlib
22
import typing
3+
import platform
34
import uuid
45
import pytest
56
import simvue
@@ -33,12 +34,12 @@ def completion_callback(*_, trigger=trigger, **__):
3334
run = simvue.Run()
3435
run.init(
3536
f"test_executor_{'success' if successful else 'fail'}",
36-
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
37+
tags=[platform.system(), "simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
3738
folder=f"/simvue_unit_testing/{folder_id}",
3839
retention_period="2 mins"
3940
)
4041
run.add_process(
41-
identifier=f"test_add_process_{'success' if successful else 'fail'}",
42+
identifier=f"test_add_process_{'success' if successful else 'fail'}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
4243
c=f"exit {0 if successful else 1}",
4344
executable="bash" if sys.platform != "win32" else "powershell",
4445
completion_callback=completion_callback
@@ -71,7 +72,7 @@ def test_executor_multiprocess(request: pytest.FixtureRequest) -> None:
7172
run.init(
7273
"test_executor_multiprocess",
7374
folder=f"/simvue_unit_testing/{folder_id}",
74-
tags=["simvue_client_tests", request.node.name]
75+
tags=[platform.system(), "simvue_client_tests", request.node.name]
7576
)
7677

7778
for i in range(10):
@@ -82,7 +83,7 @@ def callback(*_, evts=events, ident=i, **__):
8283
callbacks[i] = callback
8384
out_file = pathlib.Path(tempd).joinpath(f"out_file_{i}.dat")
8485
run.add_process(
85-
f"cmd_{i}",
86+
f"cmd_{i}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
8687
executable="bash",
8788
c="for i in {0..10}; do sleep 0.5; echo $i >> "+ f"{out_file}; done",
8889
completion_trigger=triggers[i],
@@ -136,10 +137,10 @@ def test_add_process_command_assembly(request: pytest.FixtureRequest) -> None:
136137
run.init(
137138
"test_advanced_executor",
138139
folder=f"/simvue_unit_testing/{folder_id}",
139-
tags=["simvue_client_tests", request.node.name]
140+
tags=[platform.system(), "simvue_client_tests", request.node.name]
140141
)
141142
run.add_process(
142-
identifier=(exe_id := "advanced_run"),
143+
identifier=(exe_id := f"advanced_run_{os.environ.get("PYTEST_XDIST_WORKER", 0)}"),
143144
executable="python",
144145
script=f"{code_file}",
145146
input_file=f"{in_file}",
@@ -162,10 +163,10 @@ def completion_callback(*_, success: dict[str, bool]=success, **__):
162163
run.init(
163164
"test_completion_callbacks_var_change",
164165
folder=f"/simvue_unit_testing/{folder_id}",
165-
tags=["simvue_client_tests", request.node.name]
166+
tags=[platform.system(), "simvue_client_tests", request.node.name]
166167
)
167168
run.add_process(
168-
identifier="test_completion_callbacks_var_change",
169+
identifier=f"test_completion_callbacks_var_change_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
169170
executable="bash",
170171
c="exit 0",
171172
completion_callback=completion_callback
@@ -190,10 +191,10 @@ def test_completion_trigger_set(request: pytest.FixtureRequest) -> None:
190191
run.init(
191192
"test_completion_trigger_set",
192193
folder=f"/simvue_unit_testing/{folder_id}",
193-
tags=["simvue_client_tests", request.node.name]
194+
tags=[platform.system(), "simvue_client_tests", request.node.name]
194195
)
195196
run.add_process(
196-
identifier="test_completion_trigger_set",
197+
identifier=f"test_completion_trigger_set_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
197198
executable="bash",
198199
c="exit 0",
199200
completion_trigger=trigger
@@ -221,10 +222,10 @@ def completion_callback(*_, trigger=trigger, **__):
221222
run.init(
222223
"test_completion_callbacks_trigger_set",
223224
folder="/simvue_unit_testing",
224-
tags=["simvue_client_tests", request.node.name]
225+
tags=[platform.system(), "simvue_client_tests", request.node.name]
225226
)
226227
run.add_process(
227-
identifier="test_completion_callbacks_trigger_set",
228+
identifier=f"test_completion_callbacks_trigger_set_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
228229
executable="bash",
229230
c="exit 0",
230231
completion_callback=completion_callback

‎tests/functional/test_run_artifact_upload.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import tempfile
88
import pytest
99

10-
from simvue.api.objects import Run, FileArtifact, storage
10+
from simvue.api.objects import Run, FileArtifact
1111
from simvue.api.objects.folder import Folder
1212

1313

@@ -20,21 +20,23 @@ def test_add_artifact_to_run() -> None:
2020
_run.status = "running"
2121
_run.commit()
2222

23-
with tempfile.NamedTemporaryFile() as tempf:
23+
with tempfile.NamedTemporaryFile(delete=False) as tempf:
2424
with open(tempf.name, "w") as in_f:
2525
in_f.write("Hello")
2626

2727
_artifact = FileArtifact.new(
2828
name=f"test_{_uuid}",
2929
storage=None,
30-
file_path=pathlib.Path(tempf.name),
30+
file_path=(_temp_file := pathlib.Path(tempf.name)),
3131
mime_type=None,
3232
metadata=None
3333
)
3434
_artifact.attach_to_run(_run.id, "input")
3535
_run.status = "completed"
3636
_run.commit()
3737
assert _run.artifacts
38+
_temp_file.unlink()
3839
_run.delete()
3940
_folder.delete(recursive=True, delete_runs=True)
4041

42+

0 commit comments

Comments
 (0)