Skip to content

Commit

Permalink
DoctTest line numbers not found due to method wrapping (ipython#8861)
Browse files Browse the repository at this point in the history
  • Loading branch information
denivyruck authored and Kojoley committed Feb 8, 2022
1 parent e3125d3 commit dacc63f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions IPython/testing/plugin/pytest_ipdoctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,18 @@ class MockAwareDocTestFinder(doctest.DocTestFinder):

def _find_lineno(self, obj, source_lines):
"""Doctest code does not take into account `@property`, this
is a hackish way to fix it.
is a hackish way to fix it. https://bugs.python.org/issue17446
https://bugs.python.org/issue17446
Wrapped Doctests will need to be unwrapped so the correct
line number is returned. This will be reported upstream. #8796
"""
if isinstance(obj, property):
obj = getattr(obj, "fget", obj)

if hasattr(obj, "__wrapped__"):
# Get the main obj in case of it being wrapped
obj = inspect.unwrap(obj)

# Type ignored because this is a private function.
return super()._find_lineno( # type:ignore[misc]
obj,
Expand Down

0 comments on commit dacc63f

Please sign in to comment.