(oldmodules)
| 265 | |
| 266 | |
| 267 | def modules_cleanup(oldmodules): |
| 268 | # Encoders/decoders are registered permanently within the internal |
| 269 | # codec cache. If we destroy the corresponding modules their |
| 270 | # globals will be set to None which will trip up the cached functions. |
| 271 | encodings = [(k, v) for k, v in sys.modules.items() |
| 272 | if k.startswith('encodings.')] |
| 273 | sys.modules.clear() |
| 274 | sys.modules.update(encodings) |
| 275 | # XXX: This kind of problem can affect more than just encodings. |
| 276 | # In particular extension modules (such as _ssl) don't cope |
| 277 | # with reloading properly. Really, test modules should be cleaning |
| 278 | # out the test specific modules they know they added (ala test_runpy) |
| 279 | # rather than relying on this function (as test_importhooks and test_pkg |
| 280 | # do currently). Implicitly imported *real* modules should be left alone |
| 281 | # (see issue 10556). |
| 282 | sys.modules.update(oldmodules) |
| 283 | |
| 284 | |
| 285 | @contextlib.contextmanager |
no test coverage detected
searching dependent graphs…