diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-05-25 00:51:58 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-05-25 00:51:58 (GMT) |
commit | 14a3dd716d2da4158739e502e8af8ef12e944cac (patch) | |
tree | b38d876499ded8041f9df25a9e6e369845c7556d /Lib/unittest.py | |
parent | db31d75eb14174e4206f0dee12705ffb0d824e77 (diff) | |
download | cpython-14a3dd716d2da4158739e502e8af8ef12e944cac.zip cpython-14a3dd716d2da4158739e502e8af8ef12e944cac.tar.gz cpython-14a3dd716d2da4158739e502e8af8ef12e944cac.tar.bz2 |
Merged revisions 72905 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72905 | benjamin.peterson | 2009-05-24 19:48:58 -0500 (Sun, 24 May 2009) | 4 lines
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/unittest.py')
-rw-r--r-- | Lib/unittest.py | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index c6d893e..cdccd8c 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'] @@ -459,6 +459,13 @@ class TestCase(object): self._result = 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 @@ -1129,37 +1136,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. @@ -1245,7 +1221,6 @@ class TestLoader(object): testMethodPrefix = 'test' sortTestMethodsUsing = staticmethod(three_way_cmp) suiteClass = TestSuite - classSuiteClass = ClassTestSuite def loadTestsFromTestCase(self, testCaseClass): """Return a suite of all tests cases contained in testCaseClass""" @@ -1255,8 +1230,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): |