mirror of
https://github.com/python/cpython.git
synced 2025-09-30 12:21:51 +00:00
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 b85c136903
)
This commit is contained in:
parent
809101f14f
commit
33a5d40de9
1 changed files with 21 additions and 8 deletions
|
@ -27,14 +27,27 @@ if sys.flags.no_site:
|
||||||
|
|
||||||
import site
|
import site
|
||||||
|
|
||||||
if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
|
|
||||||
# need to add user site directory for tests
|
OLD_SYS_PATH = None
|
||||||
try:
|
|
||||||
os.makedirs(site.USER_SITE)
|
|
||||||
site.addsitedir(site.USER_SITE)
|
def setUpModule():
|
||||||
except PermissionError as exc:
|
global OLD_SYS_PATH
|
||||||
raise unittest.SkipTest('unable to create user site directory (%r): %s'
|
OLD_SYS_PATH = sys.path[:]
|
||||||
% (site.USER_SITE, exc))
|
|
||||||
|
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):
|
class HelperFunctionsTests(unittest.TestCase):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue