summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_doctest.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-05-05 18:01:21 (GMT)
committerGitHub <noreply@github.com>2021-05-05 18:01:21 (GMT)
commit10d6f6bfd749c0e7da51a96f53ca326c336f7a00 (patch)
treeae5dc9e22210b4a6c2d65c2e2556fa9e6ed900be /Lib/test/test_doctest.py
parentce4fee210bb604726e5da0ff15952a60c2098f88 (diff)
downloadcpython-10d6f6bfd749c0e7da51a96f53ca326c336f7a00.zip
cpython-10d6f6bfd749c0e7da51a96f53ca326c336f7a00.tar.gz
cpython-10d6f6bfd749c0e7da51a96f53ca326c336f7a00.tar.bz2
bpo-35753: Fix crash in doctest with unwrap-able functions (GH-22981) (#25926)
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. We simply skip any object that throws this exception. This should handle the majority of cases. (cherry picked from commit 565a31804c1139fe7886f38af3b3923653b0c1b3) Co-authored-by: Alfred Perlstein <alfred@fb.com>
Diffstat (limited to 'Lib/test/test_doctest.py')
-rw-r--r--Lib/test/test_doctest.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 6f51b1b..828a0ff 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -15,6 +15,7 @@ import importlib.util
import unittest
import tempfile
import shutil
+import types
import contextlib
# NOTE: There are some additional tests relating to interaction with
@@ -443,7 +444,7 @@ We'll simulate a __file__ attr that ends in pyc:
>>> tests = finder.find(sample_func)
>>> print(tests) # doctest: +ELLIPSIS
- [<DocTest sample_func from ...:27 (1 example)>]
+ [<DocTest sample_func from test_doctest.py:28 (1 example)>]
The exact name depends on how test_doctest was invoked, so allow for
leading path components.
@@ -698,6 +699,18 @@ and 'int' is a type.
class TestDocTestFinder(unittest.TestCase):
+ def test_issue35753(self):
+ # This import of `call` should trigger issue35753 when
+ # `support.run_doctest` is called due to unwrap failing,
+ # however with a patched doctest this should succeed.
+ from unittest.mock import call
+ dummy_module = types.ModuleType("dummy")
+ dummy_module.__dict__['inject_call'] = call
+ try:
+ support.run_doctest(dummy_module, verbosity=True)
+ except ValueError as e:
+ raise support.TestFailed("Doctest unwrap failed") from e
+
def test_empty_namespace_package(self):
pkg_name = 'doctest_empty_pkg'
with tempfile.TemporaryDirectory() as parent_dir: