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

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