[Python-checkins] r71208 - python/trunk/Lib/unittest.py

michael.foord python-checkins at python.org
Sun Apr 5 03:15:02 CEST 2009


Author: michael.foord
Date: Sun Apr  5 03:15:01 2009
New Revision: 71208

Log:
Change the way unittest.TestSuite use their tests to always access them through iteration. Non behavior changing, this allows you to create custom subclasses that override __iter__.

Issue #5693


Modified:
   python/trunk/Lib/unittest.py

Modified: python/trunk/Lib/unittest.py
==============================================================================
--- python/trunk/Lib/unittest.py	(original)
+++ python/trunk/Lib/unittest.py	Sun Apr  5 03:15:01 2009
@@ -998,7 +998,7 @@
         self.addTests(tests)
 
     def __repr__(self):
-        return "<%s tests=%s>" % (_strclass(self.__class__), self._tests)
+        return "<%s tests=%s>" % (_strclass(self.__class__), list(self))
 
     def __eq__(self, other):
         if not isinstance(other, self.__class__):
@@ -1016,7 +1016,7 @@
 
     def countTestCases(self):
         cases = 0
-        for test in self._tests:
+        for test in self:
             cases += test.countTestCases()
         return cases
 
@@ -1036,7 +1036,7 @@
             self.addTest(test)
 
     def run(self, result):
-        for test in self._tests:
+        for test in self:
             if result.shouldStop:
                 break
             test(result)
@@ -1047,7 +1047,7 @@
 
     def debug(self):
         """Run the tests without collecting errors in a TestResult"""
-        for test in self._tests:
+        for test in self:
             test.debug()
 
 


More information about the Python-checkins mailing list