New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #11850 - Add sys.last_exc #11934
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this @robotherapist, looks good to me.
I do wonder about the "Skip this frame" thing, however I don't think we should be touching the exc traceback itself, so it's probably OK.
A couple of things before we can merge this:
- Add a changelog entry
- Add a test -- can add a check for
last_exc
totest_store_except_info_on_error
intesting/test_runner.py
.
for more information, see https://pre-commit.ci
@bluetech Does this require updating mypy? The error in
Weird it ran the first time though... I was hoping the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! See my comment about the mypy issue.
Two "procedural" notes, in case you'd like to submit more PRs in the future:
- Prefer to update the branch of PRs using
git rebase
, notgit merge
, this makes it a bit easier to handle. - Prefer to submit PRs from a branch in your fork, not from the
main
branch. This allows maintainers to update the PR if needed, and probably cause less of a mess for you as the submitter.
@@ -0,0 +1 @@ | |||
Added the new `sys.last_exc` value to `pytest_runtest_call()` in `src/_pytest/runner.py`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the changelog is intended for end-users to read, they don't really need to know about details like pytest_runtest_call
or the internal file it's done in. I suggest something like this:
Added the new `sys.last_exc` value to `pytest_runtest_call()` in `src/_pytest/runner.py`. | |
Added support for :data:`sys.last_exc` for post-mortem debugging on Python>=3.12. |
@@ -168,6 +168,8 @@ def pytest_runtest_call(item: Item) -> None: | |||
del sys.last_type | |||
del sys.last_value | |||
del sys.last_traceback | |||
if sys.version_info >= (3, 12, 0): | |||
del sys.last_exc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns it the type stub for it is just missing from typeshed (the project which provides type annotations for the standard library). I sent a fix for it, but until it's integrated (in a future mypy version), let's add type-ignores for it, like this:
del sys.last_exc | |
del sys.last_exc # type: ignore[attr-defined] |
Merged through #12027, thanks @robotherapist. |
Closes #11850