@@ -42,6 +42,9 @@ def __init__(self, root, mode):
4242 "wrapper_zip" ,
4343 )
4444 self .archive = mode not in ("venv" , "pyvenv" , "wrapper" )
45+ self .temporary_runtime = (
46+ mode != "pyvenv" or os .environ ["PYVENV_TEMPORARY" ] == "1"
47+ )
4548 self .files = runfiles .CreateOrRaise ()
4649 self .scratch = root / "temporary runtime with spaces"
4750 self .scratch .mkdir ()
@@ -155,7 +158,10 @@ def test_spaces_tmpdir_stdin_arguments_and_status(launcher, status):
155158 actual = json .loads (result .stdout )
156159 assert actual ["argv" ] == ["argument with spaces" ]
157160 assert actual ["stdin" ] == "input with spaces"
158- assert Path (actual ["executable" ]).is_relative_to (launcher .scratch )
161+ assert (
162+ Path (actual ["executable" ]).is_relative_to (launcher .scratch )
163+ == launcher .temporary_runtime
164+ )
159165 assert actual ["ignored" ] == [False , False ]
160166 assert (
161167 actual ["xoptions" ]["bootstrap_target" ]
@@ -212,7 +218,9 @@ def test_shell_handoff_exports_selected_runfiles_with_manifest(venv):
212218 root = venv .root / "provided.runfiles"
213219 root .symlink_to (os .fspath (venv .files .root ()), target_is_directory = True )
214220 manifest = venv .root / "provided.runfiles_manifest"
215- manifest .write_text ("_main/fixture " + str (venv .binary ) + "\n " )
221+ manifest .write_text (
222+ os .environ ["TEST_WORKSPACE" ] + "/fixture " + str (venv .binary ) + "\n "
223+ )
216224 result = venv .run (
217225 "echo" ,
218226 "0" ,
@@ -285,7 +293,7 @@ def test_signal_waits_for_application_cleanup(launcher, value, group):
285293 lambda : (launcher .root / "stopping" ).exists (), "cancellation did not arrive"
286294 )
287295 assert process .poll () is None
288- assert list (launcher .scratch .iterdir ())
296+ assert bool ( list (launcher .scratch .iterdir ())) == launcher . temporary_runtime
289297 process .send_signal (signal .SIGTERM )
290298 process .send_signal (signal .SIGHUP )
291299 assert process .stdin is not None
@@ -422,10 +430,13 @@ def test_relative_tmpdir_and_zip_working_directory(launcher):
422430 result = launcher .run ("echo" , "0" , environment = environment )
423431 assert result .returncode == 0 , result .stderr
424432 actual = json .loads (result .stdout )
425- assert Path (actual ["executable" ]).is_relative_to (launcher .scratch )
433+ assert (
434+ Path (actual ["executable" ]).is_relative_to (launcher .scratch )
435+ == launcher .temporary_runtime
436+ )
426437 if launcher .archive :
427438 assert actual ["cwd" ] == os .path .normpath (
428- str (Path (actual ["runfiles" ]) / "_main" )
439+ str (Path (actual ["runfiles" ]) / os . environ [ "TEST_WORKSPACE" ] )
429440 )
430441 launcher .cleaned ()
431442
@@ -519,7 +530,7 @@ def test_warm_shell_zip_executes_without_preparation(tmp_path):
519530 assert actual ["argv" ] == ["warm argument" ]
520531 assert actual ["runfiles" ] == prepared ["runfiles" ]
521532 assert actual ["executable" ] == prepared ["executable" ]
522- assert Path (actual ["cwd" ]).samefile (runfiles_root / "_main" )
533+ assert Path (actual ["cwd" ]).samefile (runfiles_root / os . environ [ "TEST_WORKSPACE" ] )
523534 assert actual ["xoptions" ]["warm_cache" ] == "once"
524535 assert "RULES_PYTHON_ZIP_DIR" not in actual ["xoptions" ]
525536 assert sentinel .read_text () == "keep"
@@ -757,7 +768,10 @@ def test_inherited_path_variables_cannot_select_cleanup(launcher, allocation_fai
757768 if allocation_fails :
758769 environment ["TMPDIR" ] = str (launcher .root / "missing temporary root" )
759770 result = launcher .run ("echo" , "0" , environment = environment )
760- if allocation_fails and not launcher .shell :
771+ if not launcher .temporary_runtime :
772+ assert result .returncode == 0 , result .stderr
773+ assert Path (json .loads (result .stdout )["executable" ]).is_file ()
774+ elif allocation_fails and not launcher .shell :
761775 # tempfile falls back from an invalid TMPDIR to the platform temp root.
762776 assert result .returncode == 0 , result .stderr
763777 wait_until (
@@ -843,7 +857,9 @@ def test_verbose_mode_retains_runtime(launcher):
843857 assert Path (json .loads (result .stdout )["executable" ]).is_file ()
844858 if not launcher .shell :
845859 assert "rules_python bootstrap: launching interpreter" in result .stderr
846- assert "rules_python bootstrap: retaining workspace" in result .stderr
860+ assert (
861+ "rules_python bootstrap: retaining workspace" in result .stderr
862+ ) == launcher .temporary_runtime
847863 if launcher .archive :
848864 assert "rules_python bootstrap: extracting archive" in result .stderr
849865
@@ -949,7 +965,7 @@ def test_foreground_input_and_job_control(launcher, ignored_continue):
949965 lambda : os .tcgetpgrp (terminal ) == shell_pid ,
950966 "shell did not recover foreground" ,
951967 )
952- assert list (launcher .scratch .iterdir ()), "stopped process lost its runtime"
968+ assert bool ( list (launcher .scratch .iterdir ())) == launcher . temporary_runtime
953969 stopped = launcher .root / "background-stop"
954970 # Wait in the owning shell for the new SIGTTIN stop. Sampling `ps`
955971 # here can observe the old Ctrl-Z stop before `bg` has run.
0 commit comments