1515def 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