Bug #1529297: The rewrite of doctest for Python 2.4 unintentionally
authorTim Peters <tim.peters@gmail.com>
Thu, 27 Jul 2006 23:44:37 +0000 (23:44 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 27 Jul 2006 23:44:37 +0000 (23:44 +0000)
lost that tests are sorted by name before being run.  ``DocTestFinder``
has been changed to sort the list of tests it returns.

Lib/doctest.py
Lib/test/test_doctest.py
Misc/NEWS

index 1560a18d7c80e2cd1c2941aa0d0f0a1e3a12abd6..fe734b3f82afe12474e29ed601899d3627a15c5f 100644 (file)
@@ -821,6 +821,11 @@ class DocTestFinder:
         # Recursively expore `obj`, extracting DocTests.
         tests = []
         self._find(tests, obj, name, module, source_lines, globs, {})
+        # Sort the tests by alpha order of names, for consistency in
+        # verbose-mode output.  This was a feature of doctest in Pythons
+        # <= 2.3 that got lost by accident in 2.4.  It was repaired in
+        # 2.4.4 and 2.5.
+        tests.sort()
         return tests
 
     def _from_module(self, module, object):
index 01f7acd2f5666b1dce611eeb915bb02d9f46ea91..e8379c5dc4cf073517f77a1d735653c14a5906e8 100644 (file)
@@ -419,7 +419,6 @@ methods, classmethods, staticmethods, properties, and nested classes.
 
     >>> finder = doctest.DocTestFinder()
     >>> tests = finder.find(SampleClass)
-    >>> tests.sort()
     >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      3  SampleClass
@@ -435,7 +434,6 @@ methods, classmethods, staticmethods, properties, and nested classes.
 New-style classes are also supported:
 
     >>> tests = finder.find(SampleNewStyleClass)
-    >>> tests.sort()
     >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      1  SampleNewStyleClass
@@ -475,7 +473,6 @@ functions, classes, and the `__test__` dictionary, if it exists:
     >>> # ignoring the objects since they weren't defined in m.
     >>> import test.test_doctest
     >>> tests = finder.find(m, module=test.test_doctest)
-    >>> tests.sort()
     >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      1  some_module
@@ -499,7 +496,6 @@ will only be generated for it once:
 
     >>> from test import doctest_aliases
     >>> tests = excl_empty_finder.find(doctest_aliases)
-    >>> tests.sort()
     >>> print len(tests)
     2
     >>> print tests[0].name
@@ -517,7 +513,6 @@ Empty Tests
 By default, an object with no doctests doesn't create any tests:
 
     >>> tests = doctest.DocTestFinder().find(SampleClass)
-    >>> tests.sort()
     >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      3  SampleClass
@@ -536,7 +531,6 @@ is really to support backward compatibility in what doctest.master.summarize()
 displays.
 
     >>> tests = doctest.DocTestFinder(exclude_empty=False).find(SampleClass)
-    >>> tests.sort()
     >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      3  SampleClass
@@ -557,7 +551,6 @@ DocTestFinder can be told not to look for tests in contained objects
 using the `recurse` flag:
 
     >>> tests = doctest.DocTestFinder(recurse=False).find(SampleClass)
-    >>> tests.sort()
     >>> for t in tests:
     ...     print '%2s  %s' % (len(t.examples), t.name)
      3  SampleClass
index 199fe82cda4f96a055697fcdd84d81c7e068b0ab..51de474c016f8edbd09d3e198e00e744efe18a5f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,12 @@ Core and builtins
 Library
 -------
 
+- Bug #1529297:  The rewrite of doctest for Python 2.4 unintentionally
+  lost that tests are sorted by name before being run.  This rarely
+  matters for well-written tests, but can create baffling symptoms if
+  side effects from one test to the next affect outcomes.  ``DocTestFinder``
+  has been changed to sort the list of tests it returns.
+
 - The distutils version has been changed to 2.5.0.
 
 - Bug #978833: Really close underlying socket in _socketobject.close.