diff options
5 files changed, 56 insertions, 2 deletions
diff --git a/functional_tests/test_multiprocessing/support/class.py b/functional_tests/test_multiprocessing/support/class.py new file mode 100644 index 0000000..905bcdf --- /dev/null +++ b/functional_tests/test_multiprocessing/support/class.py @@ -0,0 +1,14 @@ +class TestFunctionalTest(object): + counter = 0 + @classmethod + def setup_class(cls): + cls.counter += 1 + @classmethod + def teardown_class(cls): + cls.counter -= 1 + def _run(self): + assert self.counter==1 + def test1(self): + self._run() + def test2(self): + self._run() diff --git a/functional_tests/test_multiprocessing/test_class.py b/functional_tests/test_multiprocessing/test_class.py new file mode 100644 index 0000000..1e36ba6 --- /dev/null +++ b/functional_tests/test_multiprocessing/test_class.py @@ -0,0 +1,33 @@ +import os +import unittest + +from nose.plugins import PluginTester +from nose.plugins.skip import SkipTest +from nose.plugins.multiprocess import MultiProcess + + +support = os.path.join(os.path.dirname(__file__), 'support') + + +def setup(): + try: + import multiprocessing + if 'active' in MultiProcess.status: + raise SkipTest("Multiprocess plugin is active. Skipping tests of " + "plugin itself.") + except ImportError: + raise SkipTest("multiprocessing module not available") + + +#test case for #462 +class TestClassFixture(PluginTester, unittest.TestCase): + activate = '--processes=1' + plugins = [MultiProcess()] + suitepath = os.path.join(support, 'class.py') + + def runTest(self): + assert str(self.output).strip().endswith('OK') + assert 'Ran 2 tests' in self.output + def tearDown(self): + MultiProcess.status.pop('active') + diff --git a/functional_tests/test_multiprocessing/test_nameerror.py b/functional_tests/test_multiprocessing/test_nameerror.py index f73d02b..d3d7210 100644 --- a/functional_tests/test_multiprocessing/test_nameerror.py +++ b/functional_tests/test_multiprocessing/test_nameerror.py @@ -28,4 +28,6 @@ class TestMPNameError(PluginTester, unittest.TestCase): print str(self.output) assert 'NameError' in self.output assert "'undefined_variable' is not defined" in self.output + def tearDown(self): + MultiProcess.status.pop('active') diff --git a/functional_tests/test_multiprocessing/test_process_timeout.py b/functional_tests/test_multiprocessing/test_process_timeout.py index 535ecdb..27e0584 100644 --- a/functional_tests/test_multiprocessing/test_process_timeout.py +++ b/functional_tests/test_multiprocessing/test_process_timeout.py @@ -35,3 +35,6 @@ class TestMPTimeoutPass(TestMPTimeout): def runTest(self): assert "TimedOutException: 'timeout.test_timeout'" not in self.output assert str(self.output).strip().endswith('OK') + def tearDown(self): + MultiProcess.status.pop('active') + diff --git a/nose/plugins/multiprocess.py b/nose/plugins/multiprocess.py index 260cbf8..604752a 100644 --- a/nose/plugins/multiprocess.py +++ b/nose/plugins/multiprocess.py @@ -573,7 +573,7 @@ class MultiProcessTestRunner(TextTestRunner): for batch in self.nextBatch(case): yield batch - def checkCanSplit(self, context, fixt): + def checkCanSplit(context, fixt): """ Callback that we use to check whether the fixtures found in a context or ancestor are ones we care about. @@ -587,6 +587,7 @@ class MultiProcessTestRunner(TextTestRunner): if getattr(context, '_multiprocess_can_split_', False): return False return True + checkCanSplit = staticmethod(checkCanSplit) def sharedFixtures(self, case): context = getattr(case, 'context', None) @@ -755,7 +756,8 @@ class NoSharedFixtureContextSuite(ContextSuite): return try: localtests = [test for test in self._tests] - if len(localtests) > 1 and self.testQueue is not None: + if (not self.hasFixtures(MultiProcessTestRunner.checkCanSplit) + and len(localtests) > 1 and self.testQueue is not None): log.debug("queue %d tests"%len(localtests)) for test in localtests: if isinstance(test.test,nose.failure.Failure): |