You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.9 KiB
45 lines
1.9 KiB
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
|
|
index d0cd84f..9d2c28c 100644
|
|
--- a/Lib/test/test_site.py
|
|
+++ b/Lib/test/test_site.py
|
|
@@ -10,6 +10,7 @@ from test import support
|
|
from test.support import (captured_stderr, TESTFN, EnvironmentVarGuard,
|
|
change_cwd)
|
|
import builtins
|
|
+import glob
|
|
import os
|
|
import sys
|
|
import re
|
|
@@ -500,6 +501,23 @@ class ImportSideEffectTests(unittest.TestCase):
|
|
class StartupImportTests(unittest.TestCase):
|
|
|
|
def test_startup_imports(self):
|
|
+ # Get sys.path in isolated mode (python3 -I)
|
|
+ popen = subprocess.Popen([sys.executable, '-I', '-c',
|
|
+ 'import sys; print(repr(sys.path))'],
|
|
+ stdout=subprocess.PIPE,
|
|
+ encoding='utf-8')
|
|
+ stdout = popen.communicate()[0]
|
|
+ self.assertEqual(popen.returncode, 0, repr(stdout))
|
|
+ isolated_paths = eval(stdout)
|
|
+
|
|
+ # bpo-27807: Even with -I, the site module executes all .pth files
|
|
+ # found in sys.path (see site.addpackage()). Skip the test if at least
|
|
+ # one .pth file is found.
|
|
+ for path in isolated_paths:
|
|
+ pth_files = glob.glob(os.path.join(path, "*.pth"))
|
|
+ if pth_files:
|
|
+ self.skipTest(f"found {len(pth_files)} .pth files in: {path}")
|
|
+
|
|
# This tests checks which modules are loaded by Python when it
|
|
# initially starts upon startup.
|
|
popen = subprocess.Popen([sys.executable, '-I', '-v', '-c',
|
|
@@ -508,6 +526,7 @@ class StartupImportTests(unittest.TestCase):
|
|
stderr=subprocess.PIPE,
|
|
encoding='utf-8')
|
|
stdout, stderr = popen.communicate()
|
|
+ self.assertEqual(popen.returncode, 0, (stdout, stderr))
|
|
modules = eval(stdout)
|
|
|
|
self.assertIn('site', modules)
|