]> granicus.if.org Git - python/commitdiff
Merged revisions 72905 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Mon, 25 May 2009 00:51:58 +0000 (00:51 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 25 May 2009 00:51:58 +0000 (00:51 +0000)
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.
........

Doc/library/unittest.rst
Lib/test/test_unittest.py
Lib/unittest.py
Misc/NEWS

index abeb8a0ad4b5279920fb48034eae5b333bc7d060..61883f61158bb1ae1c2b97cc848447d691caab52 100644 (file)
@@ -60,8 +60,7 @@ so a new fixture is created for each test.
 
 Test suites are implemented by the :class:`TestSuite` class.  This class allows
 individual tests and test suites to be aggregated; when the suite is executed,
-all tests added directly to the suite and in "child" test suites are run.  A
-:class:`ClassTestSuite` contains the test cases of a class.
+all tests added directly to the suite and in "child" test suites are run.
 
 A test runner is an object that provides a single method,
 :meth:`~TestRunner.run`, which accepts a :class:`TestCase` or :class:`TestSuite`
@@ -1032,11 +1031,10 @@ Grouping tests
    test suites that will be used to build the suite initially. Additional methods
    are provided to add test cases and suites to the collection later on.
 
-   :class:`TestSuite` (including :class:`ClassTestSuite`) objects behave much
-   like :class:`TestCase` objects, except they do not actually implement a test.
-   Instead, they are used to aggregate tests into groups of tests that should be
-   run together. Some additional methods are available to add tests to
-   :class:`TestSuite` instances:
+   :class:`TestSuite` objects behave much like :class:`TestCase` objects, except
+   they do not actually implement a test.  Instead, they are used to aggregate
+   tests into groups of tests that should be run together. Some additional
+   methods are available to add tests to :class:`TestSuite` instances:
 
 
    .. method:: TestSuite.addTest(test)
@@ -1093,14 +1091,6 @@ Grouping tests
    is invoked by a :class:`TestRunner` rather than by the end-user test harness.
 
 
-.. class:: ClassTestSuite(tests, collected_from)
-
-   This subclass of :class:`TestSuite` repesents an aggregation of individuals
-   tests from one :class:`TestCase` class.  *tests* is an iterable of
-   :class:`TestCase` instances created from the class.  *collected_from* is the
-   class they came from.
-
-
 Loading and running tests
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -1202,12 +1192,6 @@ Loading and running tests
       This affects all the :meth:`loadTestsFrom\*` methods.
 
 
-   .. attribute:: classSuiteClass
-
-      Callable object that constructs a test suite for the tests cases from one
-      class.  The default value is :class:`ClassTestSuite`.
-
-
 .. class:: TestResult
 
    This class is used to compile information about which tests have succeeded
index e7097cc71ca701b3bf81a0a583d23610c98bf9ec..ea331808b3c13d45cb2084c8b77e58f9d13011a9 100644 (file)
@@ -106,7 +106,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)
 
 
@@ -1271,7 +1271,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
@@ -1284,7 +1284,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
@@ -1303,7 +1303,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
@@ -1316,7 +1316,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
@@ -2842,7 +2842,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)
@@ -2861,9 +2861,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):
index c6d893ea3a74ac1db4ba4dc5356f0ee417fe7d4a..cdccd8c3cc35efc7007cef0f020a5cd303567014 100644 (file)
@@ -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):
index de833bcfc8ba7979b901bb7d8256f47c62afab16..06415b9f65f3dc11cfbaa96b92f0b8d741afb24e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -32,6 +32,9 @@ Core and Builtins
 Library
 -------
 
+- In unittest, using a skipping decorator on a class is now equivalent to
+  skipping every test on the class.  The ClassTestSuite class has been removed.
+
 - Issue #6050: Don't fail extracting a directory from a zipfile if
   the directory already exists.