|
9 | 9 | from . import zipdata01
|
10 | 10 | from .._compat import ABC, Path, PurePath, FileNotFoundError
|
11 | 11 | 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 |
36 | 13 |
|
37 | 14 |
|
38 | 15 | try:
|
@@ -205,8 +182,8 @@ def tearDownClass(cls):
|
205 | 182 | pass
|
206 | 183 |
|
207 | 184 | 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) |
210 | 187 |
|
211 | 188 |
|
212 | 189 | class ZipSetup(ZipSetupBase):
|
|
0 commit comments