Skip to content

Commit cad9f27

Browse files
committed
Consolidate import_helper functions.
1 parent 38c1328 commit cad9f27

File tree

1 file changed

+3
-26
lines changed

1 file changed

+3
-26
lines changed

importlib_resources/tests/util.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,7 @@
99
from . import zipdata01
1010
from .._compat import ABC, Path, PurePath, FileNotFoundError
1111
from ..abc import ResourceReader
12-
13-
try:
14-
from test.support import modules_setup, modules_cleanup
15-
except ImportError:
16-
# Python 2.7.
17-
def modules_setup():
18-
return sys.modules.copy(),
19-
20-
def modules_cleanup(oldmodules):
21-
# Encoders/decoders are registered permanently within the internal
22-
# codec cache. If we destroy the corresponding modules their
23-
# globals will be set to None which will trip up the cached functions.
24-
encodings = [(k, v) for k, v in sys.modules.items()
25-
if k.startswith('encodings.')]
26-
sys.modules.clear()
27-
sys.modules.update(encodings)
28-
# XXX: This kind of problem can affect more than just encodings. In
29-
# particular extension modules (such as _ssl) don't cope with reloading
30-
# properly. Really, test modules should be cleaning out the test
31-
# specific modules they know they added (ala test_runpy) rather than
32-
# relying on this function (as test_importhooks and test_pkg do
33-
# currently). Implicitly imported *real* modules should be left alone
34-
# (see issue 10556).
35-
sys.modules.update(oldmodules)
12+
from ._compat import import_helper
3613

3714

3815
try:
@@ -205,8 +182,8 @@ def tearDownClass(cls):
205182
pass
206183

207184
def setUp(self):
208-
modules = modules_setup()
209-
self.addCleanup(modules_cleanup, *modules)
185+
modules = import_helper.modules_setup()
186+
self.addCleanup(import_helper.modules_cleanup, *modules)
210187

211188

212189
class ZipSetup(ZipSetupBase):

0 commit comments

Comments
 (0)