diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a802bb5..c788958c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and ## Unreleased +- [#971](https://github.com/pytask-dev/pytask/pull/971) restores help text for + PDB commands wrapped by pytask. - [#970](https://github.com/pytask-dev/pytask/pull/970) prevents tee-sys capture from replaying output that was already displayed when capture stops before its buffer is read. diff --git a/src/_pytask/debugging.py b/src/_pytask/debugging.py index 1484584e..abc63055 100644 --- a/src/_pytask/debugging.py +++ b/src/_pytask/debugging.py @@ -213,6 +213,9 @@ def do_debug(self, arg: Any) -> None: cls._recursive_debug -= 1 return ret + if hasattr(pdb_cls, "do_debug"): + do_debug.__doc__ = pdb_cls.do_debug.__doc__ + def do_continue(self, arg: Any) -> int: ret = super().do_continue(arg) if cls._recursive_debug == 0: @@ -239,16 +242,17 @@ def do_continue(self, arg: Any) -> int: self._continued = True return ret + if hasattr(pdb_cls, "do_continue"): + do_continue.__doc__ = pdb_cls.do_continue.__doc__ + do_c = do_cont = do_continue def do_quit(self, arg: Any) -> int: - """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: @@ -257,6 +261,9 @@ def do_quit(self, arg: Any) -> int: return ret + if hasattr(pdb_cls, "do_quit"): + do_quit.__doc__ = pdb_cls.do_quit.__doc__ + do_q = do_quit do_exit = do_quit diff --git a/tests/test_debugging.py b/tests/test_debugging.py index b36f0366..9df520ba 100644 --- a/tests/test_debugging.py +++ b/tests/test_debugging.py @@ -1,6 +1,7 @@ from __future__ import annotations import os +import pdb # noqa: T100 import re import sys import textwrap @@ -9,6 +10,7 @@ import click import pytest +from _pytask.debugging import PytaskPDB from _pytask.debugging import _pdbcls_callback from pytask import ExitCode from pytask import cli @@ -44,6 +46,24 @@ def test_capture_callback(value, expected, expectation): assert result == expected +def test_pdb_wrapped_commands_keep_docstrings(): + class CustomPdb(pdb.Pdb): + def do_debug(self, arg): + """Custom help for debug.""" + + def do_continue(self, arg): + """Custom help for continue.""" + + def do_quit(self, arg): + """Custom help for quit.""" + + wrapped = PytaskPDB._get_pdb_wrapper_class(CustomPdb, None, None) # type: ignore[arg-type] + + assert wrapped.do_debug.__doc__ == CustomPdb.do_debug.__doc__ + assert wrapped.do_continue.__doc__ == CustomPdb.do_continue.__doc__ + assert wrapped.do_quit.__doc__ == CustomPdb.do_quit.__doc__ + + def _flush(child): if child.isalive(): child.read()