diff options
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 4a2da32..b5fa574 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -99,6 +99,9 @@ import sys, traceback, inspect, linecache, os, re import unittest, difflib, pdb, tempfile import warnings from io import StringIO +from collections import namedtuple + +TestResults = namedtuple('TestResults', 'failed attempted') # There are 4 basic classes: # - Example: a <source, want> pair, plus an intra-docstring line number. @@ -1024,10 +1027,10 @@ class DocTestRunner: >>> tests.sort(key = lambda test: test.name) >>> for test in tests: ... print(test.name, '->', runner.run(test)) - _TestClass -> (0, 2) - _TestClass.__init__ -> (0, 2) - _TestClass.get -> (0, 2) - _TestClass.square -> (0, 1) + _TestClass -> TestResults(failed=0, attempted=2) + _TestClass.__init__ -> TestResults(failed=0, attempted=2) + _TestClass.get -> TestResults(failed=0, attempted=2) + _TestClass.square -> TestResults(failed=0, attempted=1) The `summarize` method prints a summary of all the test cases that have been run by the runner, and returns an aggregated `(f, t)` @@ -1042,7 +1045,7 @@ class DocTestRunner: 7 tests in 4 items. 7 passed and 0 failed. Test passed. - (0, 7) + TestResults(failed=0, attempted=7) The aggregated number of tried examples and failed examples is also available via the `tries` and `failures` attributes: @@ -1285,7 +1288,7 @@ class DocTestRunner: # Record and return the number of failures and tries. self.__record_outcome(test, failures, tries) - return failures, tries + return TestResults(failures, tries) def __record_outcome(self, test, f, t): """ @@ -1417,7 +1420,7 @@ class DocTestRunner: print("***Test Failed***", totalf, "failures.") elif verbose: print("Test passed.") - return totalf, totalt + return TestResults(totalf, totalt) #///////////////////////////////////////////////////////////////// # Backward compatibility cruft to maintain doctest.master. @@ -1688,7 +1691,7 @@ class DebugRunner(DocTestRunner): ... ''', {}, 'foo', 'foo.py', 0) >>> runner.run(test) - (0, 1) + TestResults(failed=0, attempted=1) >>> test.globs {} @@ -1818,7 +1821,7 @@ def testmod(m=None, name=None, globs=None, verbose=None, else: master.merge(runner) - return runner.failures, runner.tries + return TestResults(runner.failures, runner.tries) def testfile(filename, module_relative=True, name=None, package=None, globs=None, verbose=None, report=True, optionflags=0, @@ -1939,7 +1942,7 @@ def testfile(filename, module_relative=True, name=None, package=None, else: master.merge(runner) - return runner.failures, runner.tries + return TestResults(runner.failures, runner.tries) def run_docstring_examples(f, globs, verbose=False, name="NoName", compileflags=None, optionflags=0): @@ -1998,7 +2001,7 @@ class Tester: (f,t) = self.testrunner.run(test) if self.verbose: print(f, "of", t, "examples failed in string", name) - return (f,t) + return TestResults(f,t) def rundoc(self, object, name=None, module=None): f = t = 0 @@ -2007,7 +2010,7 @@ class Tester: for test in tests: (f2, t2) = self.testrunner.run(test) (f,t) = (f+f2, t+t2) - return (f,t) + return TestResults(f,t) def rundict(self, d, name, module=None): import types |