diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-04-20 11:39:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-20 11:39:39 (GMT) |
commit | b85c136903c6d2368162f7c4a58f258c9c69ead0 (patch) | |
tree | 0d4fd0b8b00d9f2dc4e240f01238c8dacccb0bff | |
parent | b4dc6af7a7862a8996cffed30d39d6add5ee58a3 (diff) | |
download | cpython-b85c136903c6d2368162f7c4a58f258c9c69ead0.zip cpython-b85c136903c6d2368162f7c4a58f258c9c69ead0.tar.gz cpython-b85c136903c6d2368162f7c4a58f258c9c69ead0.tar.bz2 |
bpo-30108: Restore sys.path in test_site (#1197)
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.
-rw-r--r-- | Lib/test/test_site.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 342ec9e..4029617 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -27,14 +27,27 @@ if sys.flags.no_site: import site -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 PermissionError 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): |