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
@@ -512,6 +513,23 @@ def test_license_exists_at_url(self):
512
513
class StartupImportTests (unittest .TestCase ):
513
514
514
515
def test_startup_imports (self ):
516
+ # Get sys.path in isolated mode (python3 -I)
517
+ popen = subprocess .Popen ([sys .executable , '-I' , '-c' ,
518
+ 'import sys; print(repr(sys.path))' ],
519
+ stdout = subprocess .PIPE ,
520
+ encoding = 'utf-8' )
521
+ stdout = popen .communicate ()[0 ]
522
+ self .assertEqual (popen .returncode , 0 , repr (stdout ))
523
+ isolated_paths = eval (stdout )
524
+
525
+ # bpo-27807: Even with -I, the site module executes all .pth files
526
+ # found in sys.path (see site.addpackage()). Skip the test if at least
527
+ # one .pth file is found.
528
+ for path in isolated_paths :
529
+ pth_files = glob .glob (os .path .join (path , "*.pth" ))
530
+ if pth_files :
531
+ self .skipTest (f"found { len (pth_files )} .pth files in: { path } " )
532
+
515
533
# This tests checks which modules are loaded by Python when it
516
534
# initially starts upon startup.
517
535
popen = subprocess .Popen ([sys .executable , '-I' , '-v' , '-c' ,
@@ -520,6 +538,7 @@ def test_startup_imports(self):
520
538
stderr = subprocess .PIPE ,
521
539
encoding = 'utf-8' )
522
540
stdout , stderr = popen .communicate ()
541
+ self .assertEqual (popen .returncode , 0 , (stdout , stderr ))
523
542
modules = eval (stdout )
524
543
525
544
self .assertIn ('site' , modules )
0 commit comments