Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes Class Reference
Inheritance diagram for
Inheritance graph
Collaboration diagram for
Collaboration graph

List of all members.

Public Member Functions

def __init__
def __enter__
def __exit__

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

Context manager to force import to return a new module reference.

This is useful for testing module-level behaviours, such as
the emission of a DeprecationWarning on import.

Use like this:

    with CleanImport("foo"):
        importlib.import_module("foo") # new reference

Definition at line 724 of file

Constructor & Destructor Documentation

def (   self,

Definition at line 736 of file

00737     def __init__(self, *module_names):
00738         self.original_modules = sys.modules.copy()
00739         for module_name in module_names:
00740             if module_name in sys.modules:
00741                 module = sys.modules[module_name]
00742                 # It is possible that module_name is just an alias for
00743                 # another module (e.g. stub for modules renamed in 3.x).
00744                 # In that case, we also need delete the real module to clear
00745                 # the import cache.
00746                 if module.__name__ != module_name:
00747                     del sys.modules[module.__name__]
00748                 del sys.modules[module_name]

Here is the caller graph for this function:

Member Function Documentation

Definition at line 749 of file

00750     def __enter__(self):
00751         return self

def (   self,

Definition at line 752 of file

00753     def __exit__(self, *ignore_exc):
00754         sys.modules.update(self.original_modules)

Here is the caller graph for this function:

Member Data Documentation

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 737 of file

The documentation for this class was generated from the following file: