MCPcopy Create free account
hub / github.com/celery/celery / reset_modules

Function reset_modules

t/unit/conftest.py:675–691  ·  view source on GitHub ↗

Remove modules from :data:`sys.modules` by name, and reset back again when the test/context returns. Example:: >>> with conftest.reset_modules('celery.result', 'celery.app.base'): ... pass

(*modules)

Source from the content-addressed store, hash-verified

673
674@contextmanager
675def reset_modules(*modules):
676 """Remove modules from :data:`sys.modules` by name,
677 and reset back again when the test/context returns.
678 Example::
679 >>> with conftest.reset_modules('celery.result', 'celery.app.base'):
680 ... pass
681 """
682 prev = {
683 k: sys.modules.pop(k) for k in modules if k in sys.modules
684 }
685
686 try:
687 for k in modules:
688 reload(import_module(k))
689 yield
690 finally:
691 sys.modules.update(prev)
692
693
694def get_logger_handlers(logger):

Callers

nothing calls this directly

Calls 2

popMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected