Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.support.CleanImport Class Reference
Inheritance diagram for test.support.CleanImport:
Inheritance graph
[legend]
Collaboration diagram for test.support.CleanImport:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __enter__
def __exit__

Public Attributes

 original_modules
_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 support.py.


Constructor & Destructor Documentation

def test.support.CleanImport.__init__ (   self,
  module_names 
)

Definition at line 736 of file support.py.

00736 
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 support.py.

00749 
00750     def __enter__(self):
00751         return self

def test.support.CleanImport.__exit__ (   self,
  ignore_exc 
)

Definition at line 752 of file support.py.

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

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 support.py.


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