diff options
author | Victor Stinner <vstinner@python.org> | 2022-05-06 01:41:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-06 01:41:24 (GMT) |
commit | 329afe78c3bbc234492a53f7a4084d07e215a077 (patch) | |
tree | 281fa4038479d8d6e92bfa1da96ce18aca56a8f5 /Lib/test/test_runpy.py | |
parent | 1303f8c927227b72d9ee9eae890be4692b4d4592 (diff) | |
download | cpython-329afe78c3bbc234492a53f7a4084d07e215a077.zip cpython-329afe78c3bbc234492a53f7a4084d07e215a077.tar.gz cpython-329afe78c3bbc234492a53f7a4084d07e215a077.tar.bz2 |
gh-57684: Update tests for PYTHONSAFEPATH=1 (#92358)
Fix tests failing with the PYTHONSAFEPATH=1 env var.
Enhance also -P help in Python usage (python --help).
Diffstat (limited to 'Lib/test/test_runpy.py')
-rw-r--r-- | Lib/test/test_runpy.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/Lib/test/test_runpy.py b/Lib/test/test_runpy.py index 93e1ab5..6aaa288 100644 --- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -781,13 +781,15 @@ class TestExit(unittest.TestCase): super().run(*args, **kwargs) @requires_subprocess() - def assertSigInt(self, *args, **kwargs): - proc = subprocess.run(*args, **kwargs, text=True, stderr=subprocess.PIPE) - self.assertTrue(proc.stderr.endswith("\nKeyboardInterrupt\n")) + def assertSigInt(self, cmd, *args, **kwargs): + # Use -E to ignore PYTHONSAFEPATH + cmd = [sys.executable, '-E', *cmd] + proc = subprocess.run(cmd, *args, **kwargs, text=True, stderr=subprocess.PIPE) + self.assertTrue(proc.stderr.endswith("\nKeyboardInterrupt\n"), proc.stderr) self.assertEqual(proc.returncode, self.EXPECTED_CODE) def test_pymain_run_file(self): - self.assertSigInt([sys.executable, self.ham]) + self.assertSigInt([self.ham]) def test_pymain_run_file_runpy_run_module(self): tmp = self.ham.parent @@ -800,7 +802,7 @@ class TestExit(unittest.TestCase): """ ) ) - self.assertSigInt([sys.executable, run_module], cwd=tmp) + self.assertSigInt([run_module], cwd=tmp) def test_pymain_run_file_runpy_run_module_as_main(self): tmp = self.ham.parent @@ -813,23 +815,23 @@ class TestExit(unittest.TestCase): """ ) ) - self.assertSigInt([sys.executable, run_module_as_main], cwd=tmp) + self.assertSigInt([run_module_as_main], cwd=tmp) def test_pymain_run_command_run_module(self): self.assertSigInt( - [sys.executable, "-c", "import runpy; runpy.run_module('ham')"], + ["-c", "import runpy; runpy.run_module('ham')"], cwd=self.ham.parent, ) def test_pymain_run_command(self): - self.assertSigInt([sys.executable, "-c", "import ham"], cwd=self.ham.parent) + self.assertSigInt(["-c", "import ham"], cwd=self.ham.parent) def test_pymain_run_stdin(self): - self.assertSigInt([sys.executable], input="import ham", cwd=self.ham.parent) + self.assertSigInt([], input="import ham", cwd=self.ham.parent) def test_pymain_run_module(self): ham = self.ham - self.assertSigInt([sys.executable, "-m", ham.stem], cwd=ham.parent) + self.assertSigInt(["-m", ham.stem], cwd=ham.parent) if __name__ == "__main__": |