Skip to content

Add %xmode Doctest mode for doctest friendly tracebacks#15185

Open
Jatin-Shihora wants to merge 1 commit intoipython:mainfrom
Jatin-Shihora:feat/xmode-doctest
Open

Add %xmode Doctest mode for doctest friendly tracebacks#15185
Jatin-Shihora wants to merge 1 commit intoipython:mainfrom
Jatin-Shihora:feat/xmode-doctest

Conversation

@Jatin-Shihora
Copy link
Copy Markdown

Adds a new %xmode Doctest mode that formats tracebacks for easy copy-paste into Python doctests. The output shows only the traceback header, a literal ellipsis, and the exception line:

It will look like this when set to doctest:

Traceback (most recent call last):
    ...
ZeroDivisionError: division by zero

This is useful because Python's doctest module accepts ... as a wildcard in expected traceback output, so this format lets users copy-paste IPython output directly into doctests.

changes

  • Added Doctest mode to FormattedTB.valid_modes and routing logic in ultratb.py
  • Added structured_traceback_doctest method to ListTB
  • Updated xmode config enum in interactiveshell.py
  • Updated %xmode magic docstring in basic.py
  • Added test in test_ultratb.py
  • Fixed test_xmode in test_magic.py to avoid hardcoding the mode count. So previously, 5 was hardcoded in the range, so updated it to use the mode count based on the size of the list.
  • Added whatsnew entry

Closes #14925

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement %xmode Doctest

1 participant