Blame SOURCES/00345-fix-test_site-with-extra-pth-files.patch

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