summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-20 09:52:41 -0700
committerGitHub <noreply@github.com>2021-10-20 18:52:41 +0200
commit919268316582c6ac47960c2e5dd2ee1682371494 (patch)
tree0a97b0ce7aa74c69ec31711c9a3f9ffa58c26a03
parent88f4ec88e282bf861f0af2d237e9fe28fbc8deac (diff)
downloadcpython-git-919268316582c6ac47960c2e5dd2ee1682371494.tar.gz
bpo-45229: Make doctest tests discoverable (GH-28986) (GH-29096)
(cherry picked from commit 8d6740f489fca67a44de165d29d9e0ad86285779) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r--Lib/test/test_doctest.py20
-rw-r--r--Lib/test/test_doctest2.py21
2 files changed, 18 insertions, 23 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 3efe5dafc2..af5513c631 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -3091,20 +3091,11 @@ def test_no_trailing_whitespace_stripping():
patches that contain trailing whitespace. More info on Issue 24746.
"""
-######################################################################
-## Main
-######################################################################
-
-def test_main():
- # Check the doctest cases in doctest itself:
- ret = support.run_doctest(doctest, verbosity=True)
- # Check the doctest cases defined here:
- from test import test_doctest
- support.run_doctest(test_doctest, verbosity=True)
-
- # Run unittests
- support.run_unittest(__name__)
+def load_tests(loader, tests, pattern):
+ tests.addTest(doctest.DocTestSuite(doctest))
+ tests.addTest(doctest.DocTestSuite())
+ return tests
def test_coverage(coverdir):
@@ -3117,8 +3108,9 @@ def test_coverage(coverdir):
r.write_results(show_missing=True, summary=True,
coverdir=coverdir)
+
if __name__ == '__main__':
if '-c' in sys.argv:
test_coverage('/tmp/doctest.cover')
else:
- test_main()
+ unittest.main()
diff --git a/Lib/test/test_doctest2.py b/Lib/test/test_doctest2.py
index 347a143641..ab8a069673 100644
--- a/Lib/test/test_doctest2.py
+++ b/Lib/test/test_doctest2.py
@@ -13,7 +13,6 @@ the example. It should be ignored:
import sys
import unittest
-from test import support
if sys.flags.optimize >= 2:
raise unittest.SkipTest("Cannot test docstrings with -O2")
@@ -107,17 +106,21 @@ class C(object):
"""
return val
-def test_main():
- from test import test_doctest2
- EXPECTED = 19
- f, t = support.run_doctest(test_doctest2)
- if t != EXPECTED:
- raise support.TestFailed("expected %d tests to run, not %d" %
- (EXPECTED, t))
+
+class Test(unittest.TestCase):
+ def test_testmod(self):
+ import doctest, sys
+ EXPECTED = 19
+ f, t = doctest.testmod(sys.modules[__name__])
+ if f:
+ self.fail("%d of %d doctests failed" % (f, t))
+ if t != EXPECTED:
+ self.fail("expected %d tests to run, not %d" % (EXPECTED, t))
+
# Pollute the namespace with a bunch of imported functions and classes,
# to make sure they don't get tested.
from doctest import *
if __name__ == '__main__':
- test_main()
+ unittest.main()