Skip to content
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

Copy docstrings to wrapped pdb methods #12947

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions changelog/12946.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed missing help for :mod:`pdb` commands wrapped by pytest.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional)

Suggested change
Fixed missing help for :mod:`pdb` commands wrapped by pytest.
Fixed missing help for :mod:`pdb` commands wrapped by pytest -- by :user:`adamchainz`.

17 changes: 11 additions & 6 deletions src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def do_debug(self, arg):
cls._recursive_debug -= 1
return ret

do_debug.__doc__ = pdb_cls.do_debug.__doc__

def do_continue(self, arg):
ret = super().do_continue(arg)
if cls._recursive_debug == 0:
Expand All @@ -185,22 +187,25 @@ def do_continue(self, arg):
self._continued = True
return ret

do_continue.__doc__ = pdb_cls.do_continue.__doc__

do_c = do_cont = do_continue

def do_quit(self, arg):
"""Raise Exit outcome when quit command is used in pdb.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep this as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to copy the original docstring from do_quit, which is the purpose of the PR... turning into a comment makes sure we do not lose that information.

This is a bit of a hack - it would be better if BdbQuit
could be handled, but this would require to wrap the
whole pytest run, and adjust the report etc.
"""
# Raise Exit outcome when quit command is used in pdb.
#
# This is a bit of a hack - it would be better if BdbQuit
# could be handled, but this would require to wrap the
# whole pytest run, and adjust the report etc.
ret = super().do_quit(arg)

if cls._recursive_debug == 0:
outcomes.exit("Quitting debugger")

return ret

do_quit.__doc__ = pdb_cls.do_quit.__doc__

do_q = do_quit
do_exit = do_quit

Expand Down
68 changes: 68 additions & 0 deletions testing/test_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
def interaction(self, *args):
called.append("interaction")

# Methods which we copy the docstring over.
def do_debug(self, *args):
pass

Check warning on line 57 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L57

Added line #L57 was not covered by tests

def do_continue(self, *args):
pass

Check warning on line 60 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L60

Added line #L60 was not covered by tests

def do_quit(self, *args):
pass

Check warning on line 63 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L63

Added line #L63 was not covered by tests

_pytest._CustomPdb = _CustomPdb # type: ignore
return called

Expand All @@ -75,6 +85,16 @@
print("**CustomDebugger**")
called.append("set_trace")

# Methods which we copy the docstring over.
def do_debug(self, *args):
pass

Check warning on line 90 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L90

Added line #L90 was not covered by tests

def do_continue(self, *args):
pass

Check warning on line 93 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L93

Added line #L93 was not covered by tests

def do_quit(self, *args):
pass

Check warning on line 96 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L96

Added line #L96 was not covered by tests

_pytest._CustomDebugger = _CustomDebugger # type: ignore
yield called
del _pytest._CustomDebugger # type: ignore
Expand Down Expand Up @@ -965,6 +985,34 @@
child.sendeof()
self.flush(child)

def test_pdb_wrapped_commands_docstrings(self, pytester: Pytester) -> None:
p1 = pytester.makepyfile(
"""
def test_1():
assert False
"""
)

child = pytester.spawn_pytest(f"--pdb {p1}")
child.expect("Pdb")

Check warning on line 997 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L997

Added line #L997 was not covered by tests

# Verify no undocumented commands
child.sendline("help")
child.expect("Documented commands")
assert "Undocumented commands" not in child.before.decode()

Check warning on line 1002 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L1000-L1002

Added lines #L1000 - L1002 were not covered by tests

child.sendline("help continue")
child.expect("Continue execution")
child.expect("Pdb")

Check warning on line 1006 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L1004-L1006

Added lines #L1004 - L1006 were not covered by tests

child.sendline("help debug")
child.expect("Enter a recursive debugger")
child.expect("Pdb")

Check warning on line 1010 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L1008-L1010

Added lines #L1008 - L1010 were not covered by tests

child.sendline("c")
child.sendeof()
self.flush(child)

Check warning on line 1014 in testing/test_debugging.py

View check run for this annotation

Codecov / codecov/patch

testing/test_debugging.py#L1012-L1014

Added lines #L1012 - L1014 were not covered by tests


class TestDebuggingBreakpoints:
@pytest.mark.parametrize("arg", ["--pdb", ""])
Expand Down Expand Up @@ -1288,6 +1336,16 @@

def runcall(self, *args, **kwds):
print("runcall_called", args, kwds)

# Methods which we copy the docstring over.
def do_debug(self, *args):
pass

def do_continue(self, *args):
pass

def do_quit(self, *args):
pass
""",
)
result = pytester.runpytest(
Expand Down Expand Up @@ -1354,6 +1412,16 @@

def set_trace(self, *args):
print("set_trace_called", args)

# Methods which we copy the docstring over.
def do_debug(self, *args):
pass

def do_continue(self, *args):
pass

def do_quit(self, *args):
pass
""",
)
result = pytester.runpytest(str(p1), "--pdbcls=mypdb:MyPdb", syspathinsert=True)
Expand Down
Loading