Print a summary of all the test cases that have been run by this DocTestRunner, and return a TestResults instance. The optional `verbose` argument controls how detailed the summary is. If the verbosity is not specified, then the DocTestRunner's verbosity is
(self, verbose=None)
| 1615 | # Summarization |
| 1616 | #///////////////////////////////////////////////////////////////// |
| 1617 | def summarize(self, verbose=None): |
| 1618 | """ |
| 1619 | Print a summary of all the test cases that have been run by |
| 1620 | this DocTestRunner, and return a TestResults instance. |
| 1621 | |
| 1622 | The optional `verbose` argument controls how detailed the |
| 1623 | summary is. If the verbosity is not specified, then the |
| 1624 | DocTestRunner's verbosity is used. |
| 1625 | """ |
| 1626 | if verbose is None: |
| 1627 | verbose = self._verbose |
| 1628 | |
| 1629 | notests, passed, failed = [], [], [] |
| 1630 | total_tries = total_failures = total_skips = 0 |
| 1631 | |
| 1632 | for name, (failures, tries, skips) in self._stats.items(): |
| 1633 | assert failures <= tries |
| 1634 | total_tries += tries |
| 1635 | total_failures += failures |
| 1636 | total_skips += skips |
| 1637 | |
| 1638 | if tries == 0: |
| 1639 | notests.append(name) |
| 1640 | elif failures == 0: |
| 1641 | passed.append((name, tries)) |
| 1642 | else: |
| 1643 | failed.append((name, (failures, tries, skips))) |
| 1644 | |
| 1645 | ansi = _colorize.get_colors() |
| 1646 | bold_green = ansi.BOLD_GREEN |
| 1647 | bold_red = ansi.BOLD_RED |
| 1648 | green = ansi.GREEN |
| 1649 | red = ansi.RED |
| 1650 | reset = ansi.RESET |
| 1651 | yellow = ansi.YELLOW |
| 1652 | |
| 1653 | if verbose: |
| 1654 | if notests: |
| 1655 | print(f"{_n_items(notests)} had no tests:") |
| 1656 | notests.sort() |
| 1657 | for name in notests: |
| 1658 | print(f" {name}") |
| 1659 | |
| 1660 | if passed: |
| 1661 | print(f"{green}{_n_items(passed)} passed all tests:{reset}") |
| 1662 | for name, count in sorted(passed): |
| 1663 | s = "" if count == 1 else "s" |
| 1664 | print(f" {green}{count:3d} test{s} in {name}{reset}") |
| 1665 | |
| 1666 | if failed: |
| 1667 | print(f"{red}{self.DIVIDER}{reset}") |
| 1668 | print(f"{_n_items(failed)} had failures:") |
| 1669 | for name, (failures, tries, skips) in sorted(failed): |
| 1670 | print(f" {failures:3d} of {tries:3d} in {name}") |
| 1671 | |
| 1672 | if verbose: |
| 1673 | s = "" if total_tries == 1 else "s" |
| 1674 | print(f"{total_tries} test{s} in {_n_items(self._stats)}.") |