diff options
author | Steve Dower <steve.dower@python.org> | 2023-10-02 12:22:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 12:22:55 (GMT) |
commit | 1b3bc610fd40e7c26ecb98e92f37c4ed17625c41 (patch) | |
tree | 135b2fdcc2f312c67ea3fde207345502ca3d719a /Lib | |
parent | 6139bf5e0c755ed22bdfb027a5299493f0c71be9 (diff) | |
download | cpython-1b3bc610fd40e7c26ecb98e92f37c4ed17625c41.zip cpython-1b3bc610fd40e7c26ecb98e92f37c4ed17625c41.tar.gz cpython-1b3bc610fd40e7c26ecb98e92f37c4ed17625c41.tar.bz2 |
gh-83180: Made launcher treat shebang 'python' tags as low priority so that active virtual environments are preferred (GH-108101)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_launcher.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py index 362b507..bcd4ed6 100644 --- a/Lib/test/test_launcher.py +++ b/Lib/test/test_launcher.py @@ -717,3 +717,25 @@ class TestLauncher(unittest.TestCase, RunPyMixin): f"{expect} arg1 {script}", data["stdout"].strip(), ) + + def test_shebang_command_in_venv(self): + stem = "python-that-is-not-on-path" + + # First ensure that our test name doesn't exist, and the launcher does + # not match any installed env + with self.script(f'#! /usr/bin/env {stem} arg1') as script: + data = self.run_py([script], expect_returncode=103) + + with self.fake_venv() as (venv_exe, env): + # Put a real Python (ourselves) on PATH as a distraction. + # The active VIRTUAL_ENV should be preferred when the name isn't an + # exact match. + env["PATH"] = f"{Path(sys.executable).parent};{os.environ['PATH']}" + + with self.script(f'#! /usr/bin/env {stem} arg1') as script: + data = self.run_py([script], env=env) + self.assertEqual(data["stdout"].strip(), f"{venv_exe} arg1 {script}") + + with self.script(f'#! /usr/bin/env {Path(sys.executable).stem} arg1') as script: + data = self.run_py([script], env=env) + self.assertEqual(data["stdout"].strip(), f"{sys.executable} arg1 {script}") |