Skip to content

Commit 96fb9f9

Browse files
committed
🧪 Fix wrong string formatting for additional python version in tests
1 parent 8cb40a7 commit 96fb9f9

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

‎tests/conftest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def emit(self, record):
4444

4545

4646
def clear_out_files() -> None:
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"))
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"))
4949

5050
for file_obj in out_files:
5151
file_obj.unlink()

‎tests/functional/test_executor.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def completion_callback(*_, trigger=trigger, **__):
3939
retention_period="2 mins"
4040
)
4141
run.add_process(
42-
identifier=f"test_add_process_{'success' if successful else 'fail'}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
42+
identifier=f"test_add_process_{'success' if successful else 'fail'}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
4343
c=f"exit {0 if successful else 1}",
4444
executable="bash" if sys.platform != "win32" else "powershell",
4545
completion_callback=completion_callback
@@ -83,7 +83,7 @@ def callback(*_, evts=events, ident=i, **__):
8383
callbacks[i] = callback
8484
out_file = pathlib.Path(tempd).joinpath(f"out_file_{i}.dat")
8585
run.add_process(
86-
f"cmd_{i}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
86+
f"cmd_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
8787
executable="bash",
8888
c="for i in {0..10}; do sleep 0.5; echo $i >> "+ f"{out_file}; done",
8989
completion_trigger=triggers[i],
@@ -96,8 +96,8 @@ def callback(*_, evts=events, ident=i, **__):
9696
assert out_file.exists()
9797
assert triggers[i].is_set()
9898
for i in range(10):
99-
os.remove(f"test_executor_multiprocess_cmd_{i}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.err")
100-
os.remove(f"test_executor_multiprocess_cmd_{i}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.out")
99+
os.remove(f"test_executor_multiprocess_cmd_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.err")
100+
os.remove(f"test_executor_multiprocess_cmd_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.out")
101101
with contextlib.suppress(ObjectNotFoundError):
102102
folder.delete(recursive=True, delete_runs=True)
103103

@@ -140,7 +140,7 @@ def test_add_process_command_assembly(request: pytest.FixtureRequest) -> None:
140140
tags=[platform.system(), "simvue_client_tests", request.node.name]
141141
)
142142
run.add_process(
143-
identifier=(exe_id := f"advanced_run_{os.environ.get("PYTEST_XDIST_WORKER", 0)}"),
143+
identifier=(exe_id := f"advanced_run_{os.environ.get('PYTEST_XDIST_WORKER', 0)}"),
144144
executable="python",
145145
script=f"{code_file}",
146146
input_file=f"{in_file}",
@@ -166,7 +166,7 @@ def completion_callback(*_, success: dict[str, bool]=success, **__):
166166
tags=[platform.system(), "simvue_client_tests", request.node.name]
167167
)
168168
run.add_process(
169-
identifier=f"test_completion_callbacks_var_change_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
169+
identifier=f"test_completion_callbacks_var_change_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
170170
executable="bash",
171171
c="exit 0",
172172
completion_callback=completion_callback
@@ -194,7 +194,7 @@ def test_completion_trigger_set(request: pytest.FixtureRequest) -> None:
194194
tags=[platform.system(), "simvue_client_tests", request.node.name]
195195
)
196196
run.add_process(
197-
identifier=f"test_completion_trigger_set_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
197+
identifier=f"test_completion_trigger_set_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
198198
executable="bash",
199199
c="exit 0",
200200
completion_trigger=trigger
@@ -225,7 +225,7 @@ def completion_callback(*_, trigger=trigger, **__):
225225
tags=[platform.system(), "simvue_client_tests", request.node.name]
226226
)
227227
run.add_process(
228-
identifier=f"test_completion_callbacks_trigger_set_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
228+
identifier=f"test_completion_callbacks_trigger_set_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
229229
executable="bash",
230230
c="exit 0",
231231
completion_callback=completion_callback

‎tests/functional/test_run_class.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ def abort_callback(abort_run=trigger) -> None:
11381138
run._heartbeat_interval = 1
11391139
run._testing = True
11401140
run.add_process(
1141-
identifier=f"forever_long_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
1141+
identifier=f"forever_long_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
11421142
executable="bash",
11431143
c="&".join(["sleep 10"] * N_PROCESSES),
11441144
)
@@ -1195,7 +1195,7 @@ def test_abort_on_alert_raise(
11951195
run._heartbeat_interval = 1
11961196
run._testing = True
11971197
alert_id = run.create_user_alert("abort_test", trigger_abort=True)
1198-
run.add_process(identifier=f"forever_long_other_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", executable="bash", c="sleep 10")
1198+
run.add_process(identifier=f"forever_long_other_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", executable="bash", c="sleep 10")
11991199
run.log_alert(identifier=alert_id, state="critical")
12001200
_alert = Alert(identifier=alert_id)
12011201
assert _alert.get_status(run.id) == "critical"
@@ -1213,8 +1213,8 @@ def test_abort_on_alert_raise(
12131213
def test_kill_all_processes(create_plain_run: tuple[sv_run.Run, dict]) -> None:
12141214
run, _ = create_plain_run
12151215
run.config(system_metrics_interval=1)
1216-
run.add_process(identifier=f"forever_long_a_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", executable="bash", c="sleep 10000")
1217-
run.add_process(identifier=f"forever_long_b_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", executable="bash", c="sleep 10000")
1216+
run.add_process(identifier=f"forever_long_a_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", executable="bash", c="sleep 10000")
1217+
run.add_process(identifier=f"forever_long_b_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", executable="bash", c="sleep 10000")
12181218
processes = [
12191219
psutil.Process(process.pid) for process in run._executor._processes.values()
12201220
]
@@ -1321,7 +1321,7 @@ def test_reconnect_with_process() -> None:
13211321
with sv_run.Run() as new_run:
13221322
new_run.reconnect(run.id)
13231323
run.add_process(
1324-
identifier=f"test_process_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
1324+
identifier=f"test_process_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
13251325
executable="bash",
13261326
c="echo 'Hello World!'",
13271327
)

‎tests/functional/test_run_execute_process.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
def test_monitor_processes(create_plain_run_offline: tuple[Run, dict]):
1616
_run: Run
1717
_run, _ = create_plain_run_offline
18-
_run.add_process(f"process_1_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", "Hello world!", executable="echo", n=True)
19-
_run.add_process(f"process_2_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", "bash" if sys.platform != "win32" else "powershell", debug=True, c="exit 0")
20-
_run.add_process(f"process_3_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", "ls", "-ltr")
18+
_run.add_process(f"process_1_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "Hello world!", executable="echo", n=True)
19+
_run.add_process(f"process_2_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "bash" if sys.platform != "win32" else "powershell", debug=True, c="exit 0")
20+
_run.add_process(f"process_3_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", "ls", "-ltr")
2121
sender(_run._sv_obj._local_staging_file.parents[1], 1, 10, ["folders", "runs", "alerts"])
2222

2323

@@ -34,8 +34,8 @@ def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
3434
])
3535

3636
for i in range(1, 3):
37-
_run.add_process(f"process_{i}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}", executable="bash", script=temp_f.name)
38-
assert _run.executor.get_command(f"process_{i}_{os.environ.get("PYTEST_XDIST_WORKER", 0)}") == f"bash {temp_f.name}"
37+
_run.add_process(f"process_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}", executable="bash", script=temp_f.name)
38+
assert _run.executor.get_command(f"process_{i}_{os.environ.get('PYTEST_XDIST_WORKER', 0)}") == f"bash {temp_f.name}"
3939

4040

4141
time.sleep(3)
@@ -44,7 +44,7 @@ def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
4444

4545
# Check that for when one of the processes has stopped
4646
_attempts: int = 0
47-
_first_out = next(pathlib.Path.cwd().glob(f"*process_*_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.out"))
47+
_first_out = next(pathlib.Path.cwd().glob(f"*process_*_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.out"))
4848

4949
while _first_out.stat().st_size == 0 and _attempts < 10:
5050
time.sleep(1)
@@ -54,14 +54,14 @@ def test_abort_all_processes(create_plain_run: tuple[Run, dict]) -> None:
5454
raise AssertionError("Failed to terminate processes")
5555

5656
# Check the Python process did not error
57-
_out_err = pathlib.Path.cwd().glob(f"*process_*_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.err")
57+
_out_err = pathlib.Path.cwd().glob(f"*process_*_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.err")
5858
for file in _out_err:
5959
with file.open() as in_f:
6060
assert not in_f.readlines()
6161

6262
# Now check the counter in the process was terminated
6363
# just beyond the sleep time
64-
_out_files = pathlib.Path.cwd().glob(f"*process_*_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.out")
64+
_out_files = pathlib.Path.cwd().glob(f"*process_*_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.out")
6565
for file in _out_files:
6666
with file.open() as in_f:
6767
assert (lines := in_f.readlines())
@@ -88,20 +88,20 @@ def test_processes_cwd(create_plain_run: dict[Run, dict]) -> None:
8888
with open(temp_file.name, "w") as out_f:
8989
out_f.writelines([
9090
"import os\n",
91-
f"f = open('new_file_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.txt', 'w')\n",
91+
f"f = open('new_file_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.txt', 'w')\n",
9292
"f.write('Test Line')\n",
9393
"f.close()"
9494
])
9595

9696
run_id = run.id
9797
run.add_process(
98-
identifier=f"sleep_10_process_{os.environ.get("PYTEST_XDIST_WORKER", 0)}",
98+
identifier=f"sleep_10_process_{os.environ.get('PYTEST_XDIST_WORKER', 0)}",
9999
executable="python",
100100
script=temp_file.name,
101101
cwd=temp_dir
102102
)
103103
time.sleep(1)
104-
run.save_file(os.path.join(temp_dir, f"new_file_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.txt"), 'output')
104+
run.save_file(os.path.join(temp_dir, f"new_file_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.txt"), 'output')
105105

106106
client = Client()
107107

@@ -110,8 +110,8 @@ def test_processes_cwd(create_plain_run: dict[Run, dict]) -> None:
110110
client.get_artifact_as_file(run_id, os.path.basename(temp_file.name), output_dir=os.path.join(temp_dir, "downloaded"))
111111
assert filecmp.cmp(os.path.join(temp_dir, "downloaded", os.path.basename(temp_file.name)), temp_file.name)
112112

113-
client.get_artifact_as_file(run_id, f"new_file_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.txt", output_dir=os.path.join(temp_dir, "downloaded"))
114-
with open(os.path.join(temp_dir, "downloaded", f"new_file_{os.environ.get("PYTEST_XDIST_WORKER", 0)}.txt"), "r") as new_file:
113+
client.get_artifact_as_file(run_id, f"new_file_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.txt", output_dir=os.path.join(temp_dir, "downloaded"))
114+
with open(os.path.join(temp_dir, "downloaded", f"new_file_{os.environ.get('PYTEST_XDIST_WORKER', 0)}.txt"), "r") as new_file:
115115
assert new_file.read() == "Test Line"
116116
with contextlib.suppress(FileNotFoundError):
117117
os.unlink(temp_file.name)

0 commit comments

Comments
 (0)