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

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