$26 GRAYBYTE WORDPRESS FILE MANAGER $48

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/lib/python3.7/site-packages/nose/plugins/

HOME
Current File : /opt/alt/python37/lib/python3.7/site-packages/nose/plugins//isolate.py
"""The isolation plugin resets the contents of sys.modules after running
each test module or package. Use it by setting ``--with-isolation`` or the
NOSE_WITH_ISOLATION environment variable.

The effects are similar to wrapping the following functions around the
import and execution of each test module::

    def setup(module):
        module._mods = sys.modules.copy()
    
    def teardown(module):
        to_del = [ m for m in sys.modules.keys() if m not in
                   module._mods ]
        for mod in to_del:
            del sys.modules[mod]
        sys.modules.update(module._mods)

Isolation works only during lazy loading. In normal use, this is only
during discovery of modules within a directory, where the process of
importing, loading tests and running tests from each module is
encapsulated in a single loadTestsFromName call. This plugin
implements loadTestsFromNames to force the same lazy-loading there,
which allows isolation to work in directed mode as well as discovery,
at the cost of some efficiency: lazy-loading names forces full context
setup and teardown to run for each name, defeating the grouping that
is normally used to ensure that context setup and teardown are run the
fewest possible times for a given set of names.

.. warning ::

    This plugin should not be used in conjunction with other plugins
    that assume that modules, once imported, will stay imported; for
    instance, it may cause very odd results when used with the coverage
    plugin.

"""

import logging
import sys

from nose.plugins import Plugin


log = logging.getLogger('nose.plugins.isolation')

class IsolationPlugin(Plugin):
    """
    Activate the isolation plugin to isolate changes to external
    modules to a single test module or package. The isolation plugin
    resets the contents of sys.modules after each test module or
    package runs to its state before the test. PLEASE NOTE that this
    plugin should not be used with the coverage plugin, or in any other case
    where module reloading may produce undesirable side-effects.
    """
    score = 10 # I want to be last
    name = 'isolation'

    def configure(self, options, conf):
        """Configure plugin.
        """        
        Plugin.configure(self, options, conf)
        self._mod_stack = []

    def beforeContext(self):
        """Copy sys.modules onto my mod stack
        """
        mods = sys.modules.copy()
        self._mod_stack.append(mods)

    def afterContext(self):
        """Pop my mod stack and restore sys.modules to the state
        it was in when mod stack was pushed.
        """
        mods = self._mod_stack.pop()
        to_del = [ m for m in list(sys.modules.keys()) if m not in mods ]
        if to_del:
            log.debug('removing sys modules entries: %s', to_del)
            for mod in to_del:
                del sys.modules[mod]
        sys.modules.update(mods)

    def loadTestsFromNames(self, names, module=None):
        """Create a lazy suite that calls beforeContext and afterContext
        around each name. The side-effect of this is that full context
        fixtures will be set up and torn down around each test named.
        """
        # Fast path for when we don't care
        if not names or len(names) == 1:
            return 
        loader = self.loader
        plugins = self.conf.plugins
        def lazy():
            for name in names:
                plugins.beforeContext()
                yield loader.loadTestsFromName(name, module=module)
                plugins.afterContext()
        return (loader.suiteClass(lazy), [])

    def prepareTestLoader(self, loader):
        """Get handle on test loader so we can use it in loadTestsFromNames.
        """
        self.loader = loader


Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
31 Aug 2024 6.49 AM
root / 996
0755
__pycache__
--
31 Aug 2024 6.49 AM
root / 996
0755
__init__.py
6.144 KB
6 Apr 2013 5.25 AM
root / 996
0644
allmodules.py
1.68 KB
29 Sep 2012 3.18 PM
root / 996
0644
attrib.py
9.439 KB
14 Nov 2023 10.11 PM
root / 996
0644
base.py
25.447 KB
14 Nov 2023 10.11 PM
root / 996
0644
builtin.py
0.997 KB
3 Oct 2012 2.19 AM
root / 996
0644
capture.py
3.285 KB
14 Nov 2023 10.11 PM
root / 996
0644
collect.py
3.04 KB
29 Sep 2012 3.18 PM
root / 996
0644
cover.py
11.403 KB
14 Nov 2023 10.11 PM
root / 996
0644
debug.py
2.219 KB
19 Apr 2014 8.48 PM
root / 996
0644
deprecated.py
1.515 KB
19 Apr 2014 8.48 PM
root / 996
0644
doctests.py
17.068 KB
14 Nov 2023 10.11 PM
root / 996
0644
errorclass.py
7.104 KB
14 Nov 2023 10.11 PM
root / 996
0644
failuredetail.py
1.597 KB
4 Apr 2015 3.52 PM
root / 996
0644
isolate.py
3.668 KB
14 Nov 2023 10.11 PM
root / 996
0644
logcapture.py
9.139 KB
14 Nov 2023 10.11 PM
root / 996
0644
manager.py
15.212 KB
14 Nov 2023 10.11 PM
root / 996
0644
multiprocess.py
34.459 KB
14 Nov 2023 10.11 PM
root / 996
0644
plugintest.py
13.216 KB
14 Nov 2023 10.11 PM
root / 996
0644
prof.py
5.231 KB
29 Sep 2012 3.18 PM
root / 996
0644
skip.py
2.092 KB
4 Apr 2015 3.52 PM
root / 996
0644
testid.py
9.685 KB
14 Nov 2023 10.11 PM
root / 996
0644
xunit.py
11.372 KB
14 Nov 2023 10.11 PM
root / 996
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF