diff options
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | functional_tests/support/ipt/test1/tests.py | 8 | ||||
-rw-r--r-- | functional_tests/support/ipt/test2/tests.py | 9 | ||||
-rw-r--r-- | functional_tests/test_isolate_plugin.py | 57 | ||||
-rw-r--r-- | nose/plugins/isolate.py | 57 | ||||
-rw-r--r-- | setup.cfg | 2 |
6 files changed, 111 insertions, 26 deletions
@@ -11,6 +11,10 @@ DOCUMENTATION FEATURES + DO NOT deprecate -w -- make it mean what it used to mean (working dir) -- cd + to that dir before running tests + if see multiple -w, deprecation warning and push them into testNames + ADD --test argument -- so cfg files can put tests into testNames new plugin: testid diff --git a/functional_tests/support/ipt/test1/tests.py b/functional_tests/support/ipt/test1/tests.py index 695bcb4..a9595f7 100644 --- a/functional_tests/support/ipt/test1/tests.py +++ b/functional_tests/support/ipt/test1/tests.py @@ -1,7 +1,7 @@ -from ipthelp import help +import sys +print 'ipthelp', sys.modules.get('ipthelp') import ipthelp - print ipthelp -def test(): - help() +def test1(): + ipthelp.help() diff --git a/functional_tests/support/ipt/test2/tests.py b/functional_tests/support/ipt/test2/tests.py index f1879c2..1c95896 100644 --- a/functional_tests/support/ipt/test2/tests.py +++ b/functional_tests/support/ipt/test2/tests.py @@ -1,7 +1,8 @@ -from ipthelp import help -import ipthelp +import sys +print 'ipthelp', sys.modules.get('ipthelp') +import ipthelp print ipthelp -def test(): - help(1) +def test2(): + ipthelp.help(1) diff --git a/functional_tests/test_isolate_plugin.py b/functional_tests/test_isolate_plugin.py new file mode 100644 index 0000000..087dcaa --- /dev/null +++ b/functional_tests/test_isolate_plugin.py @@ -0,0 +1,57 @@ +import os +import sys +import unittest +from nose.plugins.isolate import IsolationPlugin +from nose.plugins import PluginTester + +support = os.path.join(os.path.dirname(__file__), 'support') + +class TestDiscovery(PluginTester, unittest.TestCase): + activate = '--with-isolation' + args = ['-v'] + plugins = [IsolationPlugin()] + suitepath = os.path.join(support, 'ipt') + + def runTest(self): + print str(self.output) + + for line in self.output: + if not line.strip(): + continue + if line.startswith('-'): + break + assert line.strip().endswith('ok'), \ + "Failed test: %s" % line.strip() + + +class TestLoadFromNames(PluginTester, unittest.TestCase): + activate = '--with-isolation' + args = ['-v', 'test1/tests.py', 'test2/tests.py'] + plugins = [IsolationPlugin()] + suitepath = None + + def setUp(self): + self._dir = os.getcwd() + os.chdir(os.path.join(support, 'ipt')) + super(TestLoadFromNames, self).setUp() + + def tearDown(self): + os.chdir(self._dir) + super(TestLoadFromNames, self).tearDown() + + def makeSuite(self): + return None + + def runTest(self): + print str(self.output) + + for line in self.output: + if not line.strip(): + continue + if line.startswith('-'): + break + assert line.strip().endswith('ok'), \ + "Failed test: %s" % line.strip() + +if __name__ == '__main__': + unittest.main() diff --git a/nose/plugins/isolate.py b/nose/plugins/isolate.py index 26eb8d7..05246f9 100644 --- a/nose/plugins/isolate.py +++ b/nose/plugins/isolate.py @@ -38,23 +38,46 @@ class IsolationPlugin(Plugin): plugin may not be used with the coverage plugin. """ name = 'isolation' - - def startTest(self, test): - """Save the state of sys.modules if we're starting a test module + + def configure(self, options, conf): + Plugin.configure(self, options, conf) + self._mod_stack = [] + + def beforeContext(self): + """Copy sys.modules onto my mod stack """ - if isinstance(test, TestModule): - log.debug('isolating sys.modules changes in %s', test) - self._mods = sys.modules.copy() - - def stopTest(self, test): - """Restore the saved state of sys.modules if we're ending a test module + 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. """ - if isinstance(test, TestModule): - to_del = [ m for m in sys.modules.keys() if - m not in self._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(self._mods) + mods = self._mod_stack.pop() + to_del = [ m for m in 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 startTest(self, test): +# """Save the state of sys.modules if we're starting a test module +# """ +# if isinstance(test, TestModule): +# log.debug('isolating sys.modules changes in %s', test) +# self._mods = sys.modules.copy() + +# def stopTest(self, test): +# """Restore the saved state of sys.modules if we're ending a test module +# """ +# if isinstance(test, TestModule): +# to_del = [ m for m in sys.modules.keys() if +# m not in self._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(self._mods) @@ -4,7 +4,7 @@ tag_svn_revision = 1 [nosetests] verbosity=2 -with-doctest=1 +;;with-doctest=1 ;;detailed-errors=1 ;;with-coverage=1 ;;cover-package=nose |