summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_launcher.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-05-19 23:10:38 (GMT)
committerGitHub <noreply@github.com>2022-05-19 23:10:38 (GMT)
commita2ec09b7f56578f40132ee69a39c34a3f3ec5ec5 (patch)
treef797263b017276c20c6d4ccb4eb6905c23a916fb /Lib/test/test_launcher.py
parent76fe10a89adb484c3c41df894d69dd1cfdc0fb66 (diff)
downloadcpython-a2ec09b7f56578f40132ee69a39c34a3f3ec5ec5.zip
cpython-a2ec09b7f56578f40132ee69a39c34a3f3ec5ec5.tar.gz
cpython-a2ec09b7f56578f40132ee69a39c34a3f3ec5ec5.tar.bz2
gh-92817: Fix precedence of options to py.exe launcher (GH-92988)
(cherry picked from commit 73473fdeac3ff9d75ac9d189bb8552b7459812f1) Co-authored-by: Steve Dower <steve.dower@python.org>
Diffstat (limited to 'Lib/test/test_launcher.py')
-rw-r--r--Lib/test/test_launcher.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py
index 2e10c55..aeacbbe 100644
--- a/Lib/test/test_launcher.py
+++ b/Lib/test/test_launcher.py
@@ -244,6 +244,17 @@ class RunPyMixin:
finally:
file.unlink()
+ @contextlib.contextmanager
+ def test_venv(self):
+ venv = Path.cwd() / "Scripts"
+ venv.mkdir(exist_ok=True, parents=True)
+ venv_exe = (venv / Path(sys.executable).name)
+ venv_exe.touch()
+ try:
+ yield venv_exe, {"VIRTUAL_ENV": str(venv.parent)}
+ finally:
+ shutil.rmtree(venv)
+
class TestLauncher(unittest.TestCase, RunPyMixin):
@classmethod
@@ -451,12 +462,8 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
self.assertEqual("PythonTestSuite/3.100", default)
def test_virtualenv_in_list(self):
- venv = Path.cwd() / "Scripts"
- venv.mkdir(exist_ok=True, parents=True)
- venv_exe = (venv / Path(sys.executable).name)
- venv_exe.touch()
- try:
- data = self.run_py(["-0p"], env={"VIRTUAL_ENV": str(venv.parent)})
+ with self.test_venv() as (venv_exe, env):
+ data = self.run_py(["-0p"], env=env)
for line in data["stdout"].splitlines():
m = re.match(r"\s*\*\s+(.+)$", line)
if m:
@@ -465,7 +472,7 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
else:
self.fail("did not find active venv path")
- data = self.run_py(["-0"], env={"VIRTUAL_ENV": str(venv.parent)})
+ data = self.run_py(["-0"], env=env)
for line in data["stdout"].splitlines():
m = re.match(r"\s*\*\s+(.+)$", line)
if m:
@@ -473,8 +480,17 @@ class TestLauncher(unittest.TestCase, RunPyMixin):
break
else:
self.fail("did not find active venv entry")
- finally:
- shutil.rmtree(venv)
+
+ def test_virtualenv_with_env(self):
+ with self.test_venv() as (venv_exe, env):
+ data1 = self.run_py([], env={**env, "PY_PYTHON": "-3"})
+ data2 = self.run_py(["-3"], env={**env, "PY_PYTHON": "-3"})
+ # Compare stdout, because stderr goes via ascii
+ self.assertEqual(data1["stdout"].strip(), str(venv_exe))
+ self.assertEqual(data1["SearchInfo.lowPriorityTag"], "True")
+ # Ensure passing the argument doesn't trigger the same behaviour
+ self.assertNotEqual(data2["stdout"].strip(), str(venv_exe))
+ self.assertNotEqual(data2["SearchInfo.lowPriorityTag"], "True")
def test_py_shebang(self):
with self.py_ini(TEST_PY_COMMANDS):