Changeset 132
- Timestamp:
- Sun Nov 26 22:14:08 2006
- Files:
-
- branches/new_loader/nose/suite.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
branches/new_loader/nose/suite.py
r131 r132 18 18 19 19 20 class Test Suite(unittest.TestSuite):20 class TestCollector(unittest.TestSuite): 20 20 """A test suite with setup and teardown methods. 21 21 """ 22 def __init__(self, loader=None, **kw): 23 super(TestCollector, self).__init__(**kw) 24 self.loader = loader 25 self.conf = loader.conf 26 self._collected = False 27 28 def __nonzero__(self): 29 self.collectTests() 30 return bool(self._tests) 31 32 def __len__(self): 33 self.collectTests() 34 return len(self._tests) 35 36 def __iter__(self): 37 self.collectTests() 38 return iter(self._tests) 39 22 40 def __call__(self, *arg, **kw): 23 41 self.run(*arg, **kw) … … 26 44 def id(self): 27 45 return self.__str__() 46 47 def collectTests(self): 48 pass 28 49 29 50 def run(self, result): 51 self.startTest(result) 30 52 try: 53 self.collectTests() 54 if not self: 55 return 56 try: 57 self.setUp() 58 except KeyboardInterrupt: 59 raise 60 except StopTest: 61 pass 62 except: 63 result.addError(self, sys.exc_info()) 64 return 65 for test in self: 66 log.debug("running test %s", test) 67 if result.shouldStop: 68 break 69 test(result) 31 70 try: 32 self.startTest(result) 33 try: 34 self.setUp() 35 except KeyboardInterrupt: 36 raise 37 except StopTest: 38 pass 39 except: 40 result.addError(self, sys.exc_info()) 41 return 42 for test in self._tests: 43 log.debug("running test %s", test) 44 if result.shouldStop: 45 break 46 test(result) 47 try: 48 self.tearDown() 49 except KeyboardInterrupt: 50 raise 51 except StopTest: 52 pass 53 except: 54 result.addError(self, sys.exc_info()) 55 return result 56 finally: 57 self.stopTest(result) 58 except StopTest: 59 pass 71 self.tearDown() 72 except KeyboardInterrupt: 73 raise 74 except StopTest: 75 pass 76 except: 77 result.addError(self, sys.exc_info()) 78 return result 79 finally: 80 self.stopTest(result) 60 81 61 82 def setUp(self): … … 74 95 pass 75 96 76 77 class TestCollector(TestSuite): 78 """A TestSuite that collects its own tests. 79 """ 80 def __init__(self, loader=None, **kw): 81 super(TestCollector, self).__init__(**kw) 82 self.loader = loader 83 self.conf = loader.conf 84 self._collected = False 85 86 def __nonzero__(self): 87 self.collectTests() 88 return bool(self._tests) 89 90 def __len__(self): 91 self.collectTests() 92 return len(self._tests) 93 94 def __iter__(self): 95 self.collectTests() 96 return iter(self._tests) 97 98 def collectTests(self): 99 pass 100 101 def startTest(self): 102 self.collectTests() 103 if not iter(self): 104 raise StopTest("No tests to run") 105 result.startTest(self) 97 # backwards compatibility 98 TestSuite = TestCollector 106 99 107 100
