diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-05-25 00:48:58 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-05-25 00:48:58 (GMT) |
commit | 176a56c69b1563c4a8ac0d8f974b4271177c80ee (patch) | |
tree | 2ee2f564fad89e249f2eca908525af8bdee47e03 /Lib | |
parent | a7724e59e006e1ca0a12ae6fd2eeaf895833c297 (diff) | |
download | cpython-176a56c69b1563c4a8ac0d8f974b4271177c80ee.zip cpython-176a56c69b1563c4a8ac0d8f974b4271177c80ee.tar.gz cpython-176a56c69b1563c4a8ac0d8f974b4271177c80ee.tar.bz2 |
make class skipping decorators the same as skipping every test of the class
This removes ClassTestSuite and a good bit of hacks.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unittest.py | 17 | ||||
-rw-r--r-- | Lib/unittest.py | 44 |
2 files changed, 18 insertions, 43 deletions
diff --git a/Lib/test/test_unittest.py b/Lib/test/test_unittest.py index 4f89d87..9c1fe2a 100644 --- a/Lib/test/test_unittest.py +++ b/Lib/test/test_unittest.py @@ -107,7 +107,7 @@ class TestHashing(object): # List subclass we can add attributes to. class MyClassSuite(list): - def __init__(self, tests, klass): + def __init__(self, tests): super(MyClassSuite, self).__init__(tests) @@ -1262,7 +1262,7 @@ class Test_TestLoader(TestCase): tests = [Foo('test_1'), Foo('test_2')] loader = unittest.TestLoader() - loader.classSuiteClass = MyClassSuite + loader.suiteClass = list self.assertEqual(loader.loadTestsFromTestCase(Foo), tests) # It is implicit in the documentation for TestLoader.suiteClass that @@ -1275,7 +1275,7 @@ class Test_TestLoader(TestCase): def foo_bar(self): pass m.Foo = Foo - tests = [unittest.ClassTestSuite([Foo('test_1'), Foo('test_2')], Foo)] + tests = [[Foo('test_1'), Foo('test_2')]] loader = unittest.TestLoader() loader.suiteClass = list @@ -1294,7 +1294,7 @@ class Test_TestLoader(TestCase): tests = [Foo('test_1'), Foo('test_2')] loader = unittest.TestLoader() - loader.classSuiteClass = MyClassSuite + loader.suiteClass = list self.assertEqual(loader.loadTestsFromName('Foo', m), tests) # It is implicit in the documentation for TestLoader.suiteClass that @@ -1307,7 +1307,7 @@ class Test_TestLoader(TestCase): def foo_bar(self): pass m.Foo = Foo - tests = [unittest.ClassTestSuite([Foo('test_1'), Foo('test_2')], Foo)] + tests = [[Foo('test_1'), Foo('test_2')]] loader = unittest.TestLoader() loader.suiteClass = list @@ -2871,7 +2871,7 @@ class Test_TestSkipping(TestCase): def test_dont_skip(self): pass test_do_skip = Foo("test_skip") test_dont_skip = Foo("test_dont_skip") - suite = unittest.ClassTestSuite([test_do_skip, test_dont_skip], Foo) + suite = unittest.TestSuite([test_do_skip, test_dont_skip]) events = [] result = LoggingResult(events) suite.run(result) @@ -2890,9 +2890,10 @@ class Test_TestSkipping(TestCase): record.append(1) record = [] result = unittest.TestResult() - suite = unittest.ClassTestSuite([Foo("test_1")], Foo) + test = Foo("test_1") + suite = unittest.TestSuite([test]) suite.run(result) - self.assertEqual(result.skipped, [(suite, "testing")]) + self.assertEqual(result.skipped, [(test, "testing")]) self.assertEqual(record, []) def test_expected_failure(self): diff --git a/Lib/unittest.py b/Lib/unittest.py index fce70f8..d271675 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -59,7 +59,7 @@ import warnings ############################################################################## # Exported classes and functions ############################################################################## -__all__ = ['TestResult', 'TestCase', 'TestSuite', 'ClassTestSuite', +__all__ = ['TestResult', 'TestCase', 'TestSuite', 'TextTestRunner', 'TestLoader', 'FunctionTestCase', 'main', 'defaultTestLoader', 'SkipTest', 'skip', 'skipIf', 'skipUnless', 'expectedFailure'] @@ -458,6 +458,13 @@ class TestCase(object): self._resultForDoCleanups = result result.startTest(self) + if getattr(self.__class__, "__unittest_skip__", False): + # If the whole class was skipped. + try: + result.addSkip(self, self.__class__.__unittest_skip_why__) + finally: + result.stopTest(self) + return testMethod = getattr(self, self._testMethodName) try: success = False @@ -1110,37 +1117,6 @@ class TestSuite(object): test.debug() -class ClassTestSuite(TestSuite): - """ - Suite of tests derived from a single TestCase class. - """ - - def __init__(self, tests, class_collected_from): - super(ClassTestSuite, self).__init__(tests) - self.collected_from = class_collected_from - - def id(self): - module = getattr(self.collected_from, "__module__", None) - if module is not None: - return "{0}.{1}".format(module, self.collected_from.__name__) - return self.collected_from.__name__ - - def run(self, result): - if getattr(self.collected_from, "__unittest_skip__", False): - # ClassTestSuite result pretends to be a TestCase enough to be - # reported. - result.startTest(self) - try: - result.addSkip(self, self.collected_from.__unittest_skip_why__) - finally: - result.stopTest(self) - else: - result = super(ClassTestSuite, self).run(result) - return result - - shortDescription = id - - class FunctionTestCase(TestCase): """A test case that wraps a test function. @@ -1213,7 +1189,6 @@ class TestLoader(object): testMethodPrefix = 'test' sortTestMethodsUsing = cmp suiteClass = TestSuite - classSuiteClass = ClassTestSuite def loadTestsFromTestCase(self, testCaseClass): """Return a suite of all tests cases contained in testCaseClass""" @@ -1223,8 +1198,7 @@ class TestLoader(object): testCaseNames = self.getTestCaseNames(testCaseClass) if not testCaseNames and hasattr(testCaseClass, 'runTest'): testCaseNames = ['runTest'] - suite = self.classSuiteClass(map(testCaseClass, testCaseNames), - testCaseClass) + suite = self.suiteClass(map(testCaseClass, testCaseNames)) return suite def loadTestsFromModule(self, module): |