Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/site-packages/nose/plugins/isolate.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�9�c@sWdZddlZddlZddlmZejd�Zdefd��YZdS(s�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.

i�N(tPluginsnose.plugins.isolationtIsolationPlugincBsJeZdZdZdZd�Zd�Zd�Zdd�Z	d�Z
RS(	s�
    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.
    i
t	isolationcCs tj|||�g|_dS(sConfigure plugin.
        N(Rt	configuret
_mod_stack(tselftoptionstconf((s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pyR:scCs#tjj�}|jj|�dS(s+Copy sys.modules onto my mod stack
        N(tsystmodulestcopyRtappend(Rtmods((s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pyt
beforeContext@scCs�|jj�}gtjj�D]}||kr|^q}|rqtjd|�x|D]}tj|=qZWntjj|�dS(skPop my mod stack and restore sys.modules to the state
        it was in when mod stack was pushed.
        s removing sys modules entries: %sN(RtpopRR	tkeystlogtdebugtupdate(RRtmtto_deltmod((s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pytafterContextFs.
cs]�st��dkrdS|j�|jj�����fd�}�j|�gfS(s�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.
        iNc3s=x6�D].}�j��j|d��V�j�qWdS(Ntmodule(R
tloadTestsFromNameR(tname(tloaderRtnamestplugins(s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pytlazy\s

(tlenRRRt
suiteClass(RRRR((RRRRs8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pytloadTestsFromNamesRs	cCs
||_dS(sJGet handle on test loader so we can use it in loadTestsFromNames.
        N(R(RR((s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pytprepareTestLoadercsN(t__name__t
__module__t__doc__tscoreRRR
RtNoneR R!(((s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pyR.s			(R$tloggingRtnose.pluginsRt	getLoggerRR(((s8/sys/lib/python2.7/site-packages/nose/plugins/isolate.pyt<module>$s


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.