Skip to content

[WIP/RFC] pdb: set sys.last_{type,value,traceback} in _enter_pdb#5149

Closed
blueyed wants to merge 1 commit intopytest-dev:featuresfrom
blueyed:_enter_pdb_exc_info
Closed

[WIP/RFC] pdb: set sys.last_{type,value,traceback} in _enter_pdb#5149
blueyed wants to merge 1 commit intopytest-dev:featuresfrom
blueyed:_enter_pdb_exc_info

Conversation

@blueyed
Copy link
Contributor

@blueyed blueyed commented Apr 20, 2019

This affects pytest_exception_interact (--pdb) currently only, but
makes sense for all calls to post_mortem probably, or even more in
general.

Ref: https://github.com/python/cpython/blame/9f316bd9684d27b7e21fbf43ca86dc5e65dac4af/Doc/library/sys.rst#L891-L904

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

@blueyed blueyed changed the title pdb: set sys.last_{type,value,traceback} in _enter_pdb WIP: pdb: set sys.last_{type,value,traceback} in _enter_pdb Apr 20, 2019
@blueyed blueyed changed the title WIP: pdb: set sys.last_{type,value,traceback} in _enter_pdb [WIP/RFC] pdb: set sys.last_{type,value,traceback} in _enter_pdb Apr 20, 2019
Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine / useful -- just needs a changelog entry

@blueyed
Copy link
Contributor Author

blueyed commented Apr 24, 2019

From the description it sounds like this should be set in pytest core tiself maybe even:

These three variables are not always defined; they are set when an exception is
not handled and the interpreter prints an error message and a stack traceback.

(via https://github.com/python/cpython/blame/9f316bd9684d27b7e21fbf43ca86dc5e65dac4af/Doc/library/sys.rst#L891-L904)

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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``.

@blueyed
Copy link
Contributor Author

blueyed commented Apr 29, 2019

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.
But maybe having it via the debugging plugin is the easiest to achieve this - but it should certainly be in a more central place there then.

@blueyed
Copy link
Contributor Author

blueyed commented May 9, 2019

@pytest-dev pytest-dev deleted a comment from codecov bot Oct 27, 2019
@blueyed blueyed added the PR closed due to inactivity on occasion we do rounds to close up inactive PRs, this label makes it easier to track them label Oct 27, 2019
@blueyed blueyed closed this Oct 27, 2019
@blueyed blueyed deleted the _enter_pdb_exc_info branch October 27, 2019 05:06
@blueyed
Copy link
Contributor Author

blueyed commented Oct 27, 2019

Reworked in blueyed#16, in case you are interested.

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

Labels

PR closed due to inactivity on occasion we do rounds to close up inactive PRs, this label makes it easier to track them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants