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

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