Python test.support.modules_cleanup() Examples

The following are 10 code examples of test.support.modules_cleanup(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module test.support , or try the search function .
Example #1
Source File: util.py    From pipenv with MIT License 6 votes vote down vote up
def modules_cleanup(oldmodules):
        # Encoders/decoders are registered permanently within the internal
        # codec cache. If we destroy the corresponding modules their
        # globals will be set to None which will trip up the cached functions.
        encodings = [(k, v) for k, v in sys.modules.items()
                     if k.startswith('encodings.')]
        sys.modules.clear()
        sys.modules.update(encodings)
        # XXX: This kind of problem can affect more than just encodings. In
        # particular extension modules (such as _ssl) don't cope with reloading
        # properly.  Really, test modules should be cleaning out the test
        # specific modules they know they added (ala test_runpy) rather than
        # relying on this function (as test_importhooks and test_pkg do
        # currently).  Implicitly imported *real* modules should be left alone
        # (see issue 10556).
        sys.modules.update(oldmodules) 
Example #2
Source File: util.py    From pipenv with MIT License 5 votes vote down vote up
def setUp(self):
        modules = modules_setup()
        self.addCleanup(modules_cleanup, *modules) 
Example #3
Source File: test_pkg.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.syspath
        support.modules_cleanup(*self.modules_before)
        if self.root: # Only clean if the test was actually run
            cleanout(self.root)

        # delete all modules concerning the tested hierarchy
        if self.pkgname:
            modules = [name for name in sys.modules
                       if self.pkgname in name.split('.')]
            for name in modules:
                del sys.modules[name] 
Example #4
Source File: test_zipimport.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.path
        sys.meta_path[:] = self.meta_path
        sys.path_hooks[:] = self.path_hooks
        sys.path_importer_cache.clear()
        support.modules_cleanup(*self.modules_before) 
Example #5
Source File: test_pkg.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.syspath
        support.modules_cleanup(*self.modules_before)
        if self.root: # Only clean if the test was actually run
            cleanout(self.root)

        # delete all modules concerning the tested hierarchy
        if self.pkgname:
            modules = [name for name in sys.modules
                       if self.pkgname in name.split('.')]
            for name in modules:
                del sys.modules[name] 
Example #6
Source File: test_zipimport.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.path
        sys.meta_path[:] = self.meta_path
        sys.path_hooks[:] = self.path_hooks
        sys.path_importer_cache.clear()
        support.modules_cleanup(*self.modules_before) 
Example #7
Source File: test_pkg.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.syspath
        support.modules_cleanup(*self.modules_before)
        if self.root: # Only clean if the test was actually run
            cleanout(self.root)

        # delete all modules concerning the tested hierarchy
        if self.pkgname:
            modules = [name for name in sys.modules
                       if self.pkgname in name.split('.')]
            for name in modules:
                del sys.modules[name] 
Example #8
Source File: test_zipimport.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.path
        sys.meta_path[:] = self.meta_path
        sys.path_hooks[:] = self.path_hooks
        sys.path_importer_cache.clear()
        support.modules_cleanup(*self.modules_before) 
Example #9
Source File: test_zipimport.py    From android_universal with MIT License 5 votes vote down vote up
def tearDown(self):
        sys.path[:] = self.path
        sys.meta_path[:] = self.meta_path
        sys.path_hooks[:] = self.path_hooks
        sys.path_importer_cache.clear()
        support.modules_cleanup(*self.modules_before) 
Example #10
Source File: test_sundry.py    From android_universal with MIT License 5 votes vote down vote up
def test_sundry(self):
        old_modules = support.modules_setup()
        try:
            for fn in os.listdir(scriptsdir):
                if not fn.endswith('.py'):
                    continue

                name = fn[:-3]
                if name in self.skiplist:
                    continue

                import_tool(name)
        finally:
            # Unload all modules loaded in this test
            support.modules_cleanup(*old_modules)