[WIP/RFC] pdb: set sys.last_{type,value,traceback} in _enter_pdb#5149
[WIP/RFC] pdb: set sys.last_{type,value,traceback} in _enter_pdb#5149blueyed wants to merge 1 commit intopytest-dev:featuresfrom
Conversation
This affects pytest_exception_interact (`--pdb`) currently only, but makes sense for all calls to `post_mortem` probably, or even more in general.
| rep._pdbshown = True | ||
| sys.last_type, sys.last_value, sys.last_traceback = excinfo._excinfo | ||
| post_mortem(tb) | ||
| return rep |
There was a problem hiding this comment.
Initially I wanted this to use Pdb.user_exception instead, but that would require some adjustments of (mocking) tests.
user_exception would set __exception__ into locals (but only type and value currently (https://bugs.python.org/issue36663)).
|
From the description it sounds like this should be set in pytest core tiself maybe even:
|
nicoddemus
left a comment
There was a problem hiding this comment.
That's nice indeed, just needing a new changelog. Suggestion:
``sys.excinfo`` is now set with the causing exception when entering the debugger with ``--pdb``.|
I still think it should be more generic, and not via the debugging plugin probably, i.e. everytime Python "creates" an exception (failing test, error) it should make this info available for inspection. |
|
Found it being done here already: https://github.com/blueyed/pytest/blob/73b74c74c9674947c8383f657c3a78b1d73ffe1b/src/_pytest/runner.py#L118-L131 |
|
Reworked in blueyed#16, in case you are interested. |

This affects pytest_exception_interact (
--pdb) currently only, butmakes sense for all calls to
post_mortemprobably, or even more ingeneral.
Ref: https://github.com/python/cpython/blame/9f316bd9684d27b7e21fbf43ca86dc5e65dac4af/Doc/library/sys.rst#L891-L904