summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-03-18 17:27:32 (GMT)
committerGitHub <noreply@github.com>2020-03-18 17:27:32 (GMT)
commitd18de46117d661a4acaf2380cc5ebb1cf6a000e9 (patch)
treeb054b7f0624e5a82880dba7d08af11b4ee75ea4e /Lib
parent4657a8a0d006c76699ba3d1d4d21a04860bb2586 (diff)
downloadcpython-d18de46117d661a4acaf2380cc5ebb1cf6a000e9.zip
cpython-d18de46117d661a4acaf2380cc5ebb1cf6a000e9.tar.gz
cpython-d18de46117d661a4acaf2380cc5ebb1cf6a000e9.tar.bz2
bpo-27807: Skip test_site.test_startup_imports() if pth file (GH-19060)
test_site.test_startup_imports() is now skipped if a path of sys.path contains a .pth file. Sort test_site imports.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_site.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index 6a95e33..12e357c 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -10,16 +10,17 @@ from test import support
from test.support import (captured_stderr, TESTFN, EnvironmentVarGuard,
change_cwd)
import builtins
+import encodings
+import glob
import os
-import sys
import re
-import encodings
-import urllib.request
-import urllib.error
import shutil
import subprocess
+import sys
import sysconfig
import tempfile
+import urllib.error
+import urllib.request
from unittest import mock
from copy import copy
@@ -519,6 +520,23 @@ class ImportSideEffectTests(unittest.TestCase):
class StartupImportTests(unittest.TestCase):
def test_startup_imports(self):
+ # Get sys.path in isolated mode (python3 -I)
+ popen = subprocess.Popen([sys.executable, '-I', '-c',
+ 'import sys; print(repr(sys.path))'],
+ stdout=subprocess.PIPE,
+ encoding='utf-8')
+ stdout = popen.communicate()[0]
+ self.assertEqual(popen.returncode, 0, repr(stdout))
+ isolated_paths = eval(stdout)
+
+ # bpo-27807: Even with -I, the site module executes all .pth files
+ # found in sys.path (see site.addpackage()). Skip the test if at least
+ # one .pth file is found.
+ for path in isolated_paths:
+ pth_files = glob.glob(os.path.join(path, "*.pth"))
+ if pth_files:
+ self.skipTest(f"found {len(pth_files)} .pth files in: {path}")
+
# This tests checks which modules are loaded by Python when it
# initially starts upon startup.
popen = subprocess.Popen([sys.executable, '-I', '-v', '-c',
@@ -527,6 +545,7 @@ class StartupImportTests(unittest.TestCase):
stderr=subprocess.PIPE,
encoding='utf-8')
stdout, stderr = popen.communicate()
+ self.assertEqual(popen.returncode, 0, (stdout, stderr))
modules = eval(stdout)
self.assertIn('site', modules)