Skip to content

Commit

Permalink
Copy docstrings to wrapped pdb methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Nov 8, 2024
1 parent c85faf0 commit c27a64f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
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.
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__

Check warning on line 162 in src/_pytest/debugging.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/debugging.py#L162

Added line #L162 was not covered by tests

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__

Check warning on line 190 in src/_pytest/debugging.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/debugging.py#L190

Added line #L190 was not covered by tests

do_c = do_cont = do_continue

def do_quit(self, arg):
"""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.
"""
# 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__

Check warning on line 207 in src/_pytest/debugging.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/debugging.py#L207

Added line #L207 was not covered by tests

do_q = do_quit
do_exit = do_quit

Expand Down
28 changes: 28 additions & 0 deletions testing/test_debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,34 @@ def test_1():
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")

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

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

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

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


class TestDebuggingBreakpoints:
@pytest.mark.parametrize("arg", ["--pdb", ""])
Expand Down

0 comments on commit c27a64f

Please sign in to comment.