Skip to content
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

code: handle repr'ing empty tracebacks gracefully #10907

Merged
merged 1 commit into from
Apr 13, 2023

Conversation

bluetech
Copy link
Member

By "empty traceback" I mean a traceback all of whose entries have been filtered/cut/pruned out.

Currently, if an empty traceback needs to be repr'ed, the last entry before the filtering is used instead (added in
accd962).

Showing a hidden frame is not so good IMO. This commit does the following instead:

  1. Shows details of the exception.
  2. Shows a message about how the full trace can be seen.

Example:

_____________ test _____________

E   ZeroDivisionError: division by zero
All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames.

Also handles --tb=native, though there the --full-trace bit is not shown.

This commit contains some pieces from
431ec6d (which has been reverted).

Helps towards fixing issue #1904.

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.

Looks great, thanks!

src/_pytest/_code/code.py Outdated Show resolved Hide resolved
src/_pytest/reports.py Outdated Show resolved Hide resolved
By "empty traceback" I mean a traceback all of whose entries have been
filtered/cut/pruned out.

Currently, if an empty traceback needs to be repr'ed, the last entry
before the filtering is used instead (added in
accd962).

Showing a hidden frame is not so good IMO. This commit does the
following instead:

1. Shows details of the exception.
2. Shows a message about how the full trace can be seen.

Example:

```
_____________ test _____________

E   ZeroDivisionError: division by zero
All traceback entries are hidden. Pass `--full-trace` to see hidden and internal frames.
```

Also handles `--tb=native`, though there the `--full-trace` bit is not
shown.

This commit contains some pieces from
431ec6d (which has been reverted).

Helps towards fixing issue # 1904.

Co-authored-by: Felix Hofstätter <[email protected]>
@bluetech
Copy link
Member Author

bluetech commented Apr 13, 2023

@RonnyPfannschmidt here you proposed replacing pruning with collapsing, i.e. showing "10 frames hidden by pytest" or similar. This might be good, but I think most of the time it would be redundant, people don't really care about the hidden frames. For the case where all frames are hidden, just showing a message seems good enough to me. It's not something that is really normal.

I just remembered that I should test pytest-bdd with this change, as that's the package which triggered this situation in the first place. Will do it later.

@RonnyPfannschmidt
Copy link
Member

A key bit for this would be to enable expansions in better ux

@RonnyPfannschmidt
Copy link
Member

Aka pytest-html or a potential pytest-textual allowing to expand the collapsed frames

@bluetech
Copy link
Member Author

Aka pytest-html or a potential pytest-textual allowing to expand the collapsed frames

Yea, thinking about it a bit more I definitely agree that it would be better, instead of physically cutting out the hidden frames from the traceback, to instead mark them as hidden, and leave it to the "UI" code to not show them. Will be a good improvement for the future.

@bluetech bluetech merged commit b893d2a into pytest-dev:main Apr 13, 2023
@bluetech bluetech deleted the empty-traceback branch April 13, 2023 16:36
bluetech added a commit to bluetech/pytest that referenced this pull request Apr 16, 2023
bluetech added a commit to bluetech/pytest that referenced this pull request Apr 16, 2023
bluetech added a commit that referenced this pull request Apr 16, 2023
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.

3 participants