summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-05-04 16:21:52 (GMT)
committerGitHub <noreply@github.com>2017-05-04 16:21:52 (GMT)
commit78064387e5815633168a80dcdc1bd9aec4eff46a (patch)
treee605c48c5b25c1d4b16e339f368f9f2e051716d8 /Lib/test
parent9fb061ba9ca6021055ca5a9bac193aeb1211aba0 (diff)
downloadcpython-78064387e5815633168a80dcdc1bd9aec4eff46a.zip
cpython-78064387e5815633168a80dcdc1bd9aec4eff46a.tar.gz
cpython-78064387e5815633168a80dcdc1bd9aec4eff46a.tar.bz2
bpo-30108: Restore sys.path in test_site (#1197) (#1459)
Add setUpModule() and tearDownModule() functions to test_site to save/restore sys.path at the module level to prevent warning if the user site directory is created, since site.addsitedir() modifies sys.path. (cherry picked from commit b85c136903c6d2368162f7c4a58f258c9c69ead0)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_site.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py
index d9a9324..3ba5dca 100644
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -24,14 +24,27 @@ if "site" in sys.modules:
else:
raise unittest.SkipTest("importation of site.py suppressed")
-if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
- # need to add user site directory for tests
- try:
- os.makedirs(site.USER_SITE)
- site.addsitedir(site.USER_SITE)
- except OSError as exc:
- raise unittest.SkipTest('unable to create user site directory (%r): %s'
- % (site.USER_SITE, exc))
+
+OLD_SYS_PATH = None
+
+
+def setUpModule():
+ global OLD_SYS_PATH
+ OLD_SYS_PATH = sys.path[:]
+
+ if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
+ # need to add user site directory for tests
+ try:
+ os.makedirs(site.USER_SITE)
+ # modify sys.path: will be restored by tearDownModule()
+ site.addsitedir(site.USER_SITE)
+ except PermissionError as exc:
+ raise unittest.SkipTest('unable to create user site directory (%r): %s'
+ % (site.USER_SITE, exc))
+
+
+def tearDownModule():
+ sys.path[:] = OLD_SYS_PATH
class HelperFunctionsTests(unittest.TestCase):