@@ -82,7 +82,7 @@ def _kill_user_processes(test_username: str) -> None:
8282 subprocess .run (kill_cmd , shell = True )
8383
8484
85- def _create_test_script_command (env_dir : str , tester_type : str ) -> str :
85+ def _create_test_script_command (tester_type : str ) -> str :
8686 """
8787 Return string representing a command line command to
8888 run tests.
@@ -95,9 +95,8 @@ def _create_test_script_command(env_dir: str, tester_type: str) -> str:
9595 "from testers.specs import TestSpecs" ,
9696 f"Tester(specs=TestSpecs.from_json(sys.stdin.read())).run()" ,
9797 ]
98- python_ex = os .path .join (os .path .join (TEST_SCRIPT_DIR , env_dir ), "bin" , "python" )
9998 python_str = "; " .join (python_lines )
100- return f"{ python_ex } -c '{ python_str } '"
99+ return f"\" ${{PYTHON}} \" -c '{ python_str } '"
101100
102101
103102def get_available_port (min_ , max_ , host : str = "localhost" ) -> str :
@@ -174,9 +173,8 @@ def _run_test_specs(
174173
175174 for settings in test_settings ["testers" ]:
176175 tester_type = settings ["tester_type" ]
177- env_dir = settings .get ("_env_loc" )
178176
179- cmd_str = _create_test_script_command (env_dir , tester_type )
177+ cmd_str = _create_test_script_command (tester_type )
180178 args = cmd .format (cmd_str )
181179
182180 for test_data in settings ["test_data" ]:
@@ -198,7 +196,7 @@ def _run_test_specs(
198196 stdin = subprocess .PIPE ,
199197 preexec_fn = set_rlimits_before_test ,
200198 universal_newlines = True ,
201- env = {** os .environ , ** env_vars },
199+ env = {** os .environ , ** env_vars , ** settings [ "_env" ] },
202200 )
203201 try :
204202 settings_json = json .dumps ({** settings , "test_data" : test_data })
@@ -356,20 +354,15 @@ def update_test_settings(user, settings_id, test_settings, file_url):
356354 tester_type = tester_settings ["tester_type" ]
357355 if tester_type not in installed_testers :
358356 raise Exception (f"tester { tester_type } is not installed" )
357+ env_dir = os .path .join (settings_dir , f"{ tester_type } _{ i } " )
359358 tester_install = importlib .import_module (f"autotest_server.testers.{ tester_type } .setup" )
360- if tester_settings .get ("env_data" ):
361- env_dir = os .path .join (settings_dir , f"{ tester_type } _{ i } " )
362- tester_settings ["_env_loc" ] = env_dir
363- try :
364- tester_install .create_environment (tester_settings )
365- except Exception as e :
366- raise Exception (f"create tester environment failed:\n { e } " ) from e
367- else :
368- default_env = os .path .join (TEST_SCRIPT_DIR , DEFAULT_ENV_DIR )
369- if not os .path .isdir (default_env ):
370- subprocess .run ([sys .executable , "-m" , "venv" , default_env ], check = True )
371-
372- tester_settings ["_env_loc" ] = default_env
359+ default_env = os .path .join (TEST_SCRIPT_DIR , DEFAULT_ENV_DIR )
360+ if not os .path .isdir (default_env ):
361+ subprocess .run ([sys .executable , "-m" , "venv" , default_env ], check = True )
362+ try :
363+ tester_settings ["_env" ] = tester_install .create_environment (tester_settings , env_dir , default_env )
364+ except Exception as e :
365+ raise Exception (f"create tester environment failed:\n { e } " ) from e
373366 test_settings ["testers" ][i ] = tester_settings
374367 test_settings ["_files" ] = files_dir
375368 test_settings .pop ("_error" , None )
0 commit comments