def _flatten(self, suite): # XXX # examine suite tests to find out if they have class # or module fixtures and group them that way into names # of test classes or modules # ALSO record all test cases in self.cases mods = {} classes = {} stack = [suite] while stack: suite = stack.pop() for test in suite: if isinstance(test, unittest.TestSuite): stack.append(test) else: testid = util.test_name(test) self.cases[testid] = test if util.has_module_fixtures(test): mods.setdefault(test.__class__.__module__, []).append( testid) elif util.has_class_fixtures(test): classes.setdefault( "%s.%s" % (test.__class__.__module__, test.__class__.__name__), []).append(testid) else: yield testid for cls in sorted(classes.keys()): yield cls for mod in sorted(mods.keys()): yield mod
def test_module_without_fixtures(self): class M(object): pass M.__name__ = "nose2.foo.bar" class C(unittest.TestCase): def runTest(self): pass C.__module__ = M.__name__ m = M() m.C = C sys.modules[M.__name__] = m try: self.assertFalse(util.has_module_fixtures(C)) self.assertFalse(util.has_module_fixtures(C())) finally: del sys.modules[M.__name__]
def test_module_with_teardown(self): class M(object): pass M.__name__ = "nose2.foo.bar" class C(unittest.TestCase): def runTest(self): pass C.__module__ = M.__name__ m = M() m.C = C m.tearDownModule = lambda: None sys.modules[M.__name__] = m try: self.assertTrue(util.has_module_fixtures(C)) self.assertTrue(util.has_module_fixtures(C())) finally: del sys.modules[M.__name__]
def _flatten(self, suite): """ Flatten test-suite into list of IDs, AND record all test case into self.cases CAVEAT: Due to current limitation of the MP plugin, examine the suite tests to find out if they have class or module fixtures and group them that way into name of test classes or module. This is aid in their dispatch. """ log.debug("Flattening test into list of IDs") mods = {} classes = {} stack = [suite] while stack: suite = stack.pop() for test in suite: if isinstance(test, unittest.TestSuite): stack.append(test) else: testid = util.test_name(test) self.cases[testid] = test if util.has_module_fixtures(test): mods.setdefault(test.__class__.__module__, []).append(testid) elif util.has_class_fixtures(test): if test.__class__.__name__ == "_MethodTestCase": # wrapped by MethodTestCase in testclasses.py test = test.obj if hasattr(test, '_testMethodName') and test._testMethodName: # test a single method under the test class yield "%s.%s.%s" % ( test.__class__.__module__, test.__class__.__name__, test._testMethodName, ) else: classes.setdefault( "%s.%s" % (test.__class__.__module__, test.__class__.__name__), []).append(testid) else: yield testid for cls in sorted(classes.keys()): yield cls for mod in sorted(mods.keys()): yield mod
def _flatten(self, suite): """ Flatten test-suite into list of IDs, AND record all test case into self.cases CAVEAT: Due to current limitation of the MP plugin, examine the suite tests to find out if they have class or module fixtures and group them that way into name of test classes or module. This is aid in their dispatch. """ log.debug("Flattening test into list of IDs") mods = {} classes = {} stack = [suite] while stack: suite = stack.pop() for test in suite: if isinstance(test, unittest.TestSuite): stack.append(test) else: testid = util.test_name(test) self.cases[testid] = test if util.has_module_fixtures(test): mods.setdefault(test.__class__.__module__, []).append( testid) elif util.has_class_fixtures(test): classes.setdefault( "%s.%s" % (test.__class__.__module__, test.__class__.__name__), []).append(testid) else: yield testid for cls in sorted(classes.keys()): yield cls for mod in sorted(mods.keys()): yield mod