Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 14 additions & 7 deletions src/_pytask/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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

Expand Down
20 changes: 20 additions & 0 deletions tests/test_debugging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import os
import pdb # noqa: T100
import re
import sys
import textwrap
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down