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)
| 1588 | # Summarization |
| 1589 | #///////////////////////////////////////////////////////////////// |
| 1590 | def summarize(self, verbose=None): |
| 1591 | """ |
| 1592 | Print a summary of all the test cases that have been run by |
| 1593 | this DocTestRunner, and return a TestResults instance. |
| 1594 | |
| 1595 | The optional `verbose` argument controls how detailed the |
| 1596 | summary is. If the verbosity is not specified, then the |
| 1597 | DocTestRunner's verbosity is used. |
| 1598 | """ |
| 1599 | if verbose is None: |
| 1600 | verbose = self._verbose |
| 1601 | |
| 1602 | notests, passed, failed = [], [], [] |
| 1603 | total_tries = total_failures = total_skips = 0 |
| 1604 | |
| 1605 | for name, (failures, tries, skips) in self._stats.items(): |
| 1606 | assert failures <= tries |
| 1607 | total_tries += tries |
| 1608 | total_failures += failures |
| 1609 | total_skips += skips |
| 1610 | |
| 1611 | if tries == 0: |
| 1612 | notests.append(name) |
| 1613 | elif failures == 0: |
| 1614 | passed.append((name, tries)) |
| 1615 | else: |
| 1616 | failed.append((name, (failures, tries, skips))) |
| 1617 | |
| 1618 | ansi = _colorize.get_colors() |
| 1619 | bold_green = ansi.BOLD_GREEN |
| 1620 | bold_red = ansi.BOLD_RED |
| 1621 | green = ansi.GREEN |
| 1622 | red = ansi.RED |
| 1623 | reset = ansi.RESET |
| 1624 | yellow = ansi.YELLOW |
| 1625 | |
| 1626 | if verbose: |
| 1627 | if notests: |
| 1628 | print(f"{_n_items(notests)} had no tests:") |
| 1629 | notests.sort() |
| 1630 | for name in notests: |
| 1631 | print(f" {name}") |
| 1632 | |
| 1633 | if passed: |
| 1634 | print(f"{green}{_n_items(passed)} passed all tests:{reset}") |
| 1635 | for name, count in sorted(passed): |
| 1636 | s = "" if count == 1 else "s" |
| 1637 | print(f" {green}{count:3d} test{s} in {name}{reset}") |
| 1638 | |
| 1639 | if failed: |
| 1640 | print(f"{red}{self.DIVIDER}{reset}") |
| 1641 | print(f"{_n_items(failed)} had failures:") |
| 1642 | for name, (failures, tries, skips) in sorted(failed): |
| 1643 | print(f" {failures:3d} of {tries:3d} in {name}") |
| 1644 | |
| 1645 | if verbose: |
| 1646 | s = "" if total_tries == 1 else "s" |
| 1647 | print(f"{total_tries} test{s} in {_n_items(self._stats)}.") |