[3.8] bpo-27807: Skip test_site.test_startup_imports() if pth file (G… · python/cpython@6056b7b (original) (raw)
`@@ -10,6 +10,7 @@
`
10
10
`from test.support import (captured_stderr, TESTFN, EnvironmentVarGuard,
`
11
11
`change_cwd)
`
12
12
`import builtins
`
``
13
`+
import glob
`
13
14
`import os
`
14
15
`import sys
`
15
16
`import re
`
`@@ -504,6 +505,23 @@ def test_license_exists_at_url(self):
`
504
505
`class StartupImportTests(unittest.TestCase):
`
505
506
``
506
507
`def test_startup_imports(self):
`
``
508
`+
Get sys.path in isolated mode (python3 -I)
`
``
509
`+
popen = subprocess.Popen([sys.executable, '-I', '-c',
`
``
510
`+
'import sys; print(repr(sys.path))'],
`
``
511
`+
stdout=subprocess.PIPE,
`
``
512
`+
encoding='utf-8')
`
``
513
`+
stdout = popen.communicate()[0]
`
``
514
`+
self.assertEqual(popen.returncode, 0, repr(stdout))
`
``
515
`+
isolated_paths = eval(stdout)
`
``
516
+
``
517
`+
bpo-27807: Even with -I, the site module executes all .pth files
`
``
518
`+
found in sys.path (see site.addpackage()). Skip the test if at least
`
``
519
`+
one .pth file is found.
`
``
520
`+
for path in isolated_paths:
`
``
521
`+
pth_files = glob.glob(os.path.join(path, "*.pth"))
`
``
522
`+
if pth_files:
`
``
523
`+
self.skipTest(f"found {len(pth_files)} .pth files in: {path}")
`
``
524
+
507
525
`# This tests checks which modules are loaded by Python when it
`
508
526
`# initially starts upon startup.
`
509
527
`popen = subprocess.Popen([sys.executable, '-I', '-v', '-c',
`
`@@ -512,6 +530,7 @@ def test_startup_imports(self):
`
512
530
`stderr=subprocess.PIPE,
`
513
531
`encoding='utf-8')
`
514
532
`stdout, stderr = popen.communicate()
`
``
533
`+
self.assertEqual(popen.returncode, 0, (stdout, stderr))
`
515
534
`modules = eval(stdout)
`
516
535
``
517
536
`self.assertIn('site', modules)
`