Skip to content

Commit 4604ba4

Browse files
committed
bpo-35753: fix doctest on unwrappables funcs 1/2
Summary: Ignore objects that inspect.unwrap throws due to too many wrappers. This is a very rare case, however it can easily be surfaced when a module under doctest imports unitest.mock.call into its namespace. This commit adds a test that should fail prior to the fix to the doctest module. Test Plan: Reviewers: Subscribers: Tasks: Tags:
1 parent ec18c46 commit 4604ba4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Lib/test/test_doctest5.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""A module to test whether doctest works properly with
2+
un-unwrappable functions.
3+
4+
See: https://bugs.python.org/issue35753
5+
"""
6+
7+
# This should trigger issue35753 when doctest called
8+
from unittest.mock import call
9+
10+
import sys
11+
import unittest
12+
from test import support
13+
if sys.flags.optimize >= 2:
14+
raise unittest.SkipTest("Cannot test docstrings with -O2")
15+
16+
17+
def test_main():
18+
from test import test_doctest5
19+
EXPECTED = 0
20+
try:
21+
f, t = support.run_doctest(test_doctest5)
22+
if t != EXPECTED:
23+
raise support.TestFailed("expected %d tests to run, not %d" %
24+
(EXPECTED, t))
25+
except ValueError as e:
26+
raise support.TestFailed("Doctest unwrap failed") from e
27+
28+
# Pollute the namespace with a bunch of imported functions and classes,
29+
# to make sure they don't get tested.
30+
# from doctest import *
31+
32+
if __name__ == '__main__':
33+
test_main()

0 commit comments

Comments
 (0)