diff --git a/Lib/site.py b/Lib/site.py index 0fc92009e1..6f02eb8aae 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -537,6 +537,8 @@ def main(): execsitecustomize() if ENABLE_USER_SITE: execusercustomize() + if '__PYVENV_LAUNCHER__' in os.environ: + del os.environ['__PYVENV_LAUNCHER__'] # Prevent extending of sys.path when python was started with -S and # site is imported later. diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py index 0ff978fc8c..c2b697cac4 100644 --- a/Lib/test/test_venv.py +++ b/Lib/test/test_venv.py @@ -46,10 +46,7 @@ class BaseTest(unittest.TestCase): self.bindir = 'bin' self.lib = ('lib', 'python%d.%d' % sys.version_info[:2]) self.include = 'include' - if sys.platform == 'darwin' and '__PYVENV_LAUNCHER__' in os.environ: - executable = os.environ['__PYVENV_LAUNCHER__'] - else: - executable = sys.executable + executable = sys.executable self.exe = os.path.split(executable)[-1] def tearDown(self): @@ -286,6 +283,9 @@ class BasicTest(BaseTest): out, err = p.communicate() self.assertEqual(out.strip(), envpy.encode()) + def test_venv_launcher_does_not_leak(self): + self.assertNotIn('__PYVENV_LAUNCHER__', os.environ) + @skipInVenv class EnsurePipTest(BaseTest):