10000 bpo-35753: Fix crash in doctest with unwrap-able functions by splbio · Pull Request #22981 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-35753: Fix crash in doctest with unwrap-able functions #22981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 5, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bpo-35753: fix doctest on unwrappables funcs 2/3
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.
  • Loading branch information
splbio committed Nov 22, 2020
commit 5b835763768db0f5c830310eacc634267c19d81c
13 changes: 13 additions & 0 deletions Lib/test/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import unittest
import tempfile
import shutil
import types
import contextlib

# NOTE: There are some additional tests relating to interaction with
Expand Down Expand Up @@ -698,6 +699,18 @@ def non_Python_modules(): r"""

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:
Expand Down
0