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):