-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Improve internal error messages #4077
Improve internal error messages #4077
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.
makes sense to me! We use UserError
in an internal tool that follows this pattern and FatalError
in pre-commit for the same idea
It turns out that we almost have this already: I have this working locally, need to review the code for candidates to use This will go into |
This prevents an enormous and often useless stack trace from showing to end users. Fix pytest-dev#3867 Fix pytest-dev#2293
e86e835
to
5436e42
Compare
Codecov Report
@@ Coverage Diff @@
## features #4077 +/- ##
============================================
+ Coverage 94.37% 94.57% +0.19%
============================================
Files 109 109
Lines 23942 23945 +3
Branches 2363 2361 -2
============================================
+ Hits 22596 22645 +49
+ Misses 1028 994 -34
+ Partials 318 306 -12
Continue to review full report at Codecov.
|
Currently some usage errors produce very ugly traceback with pytest's internals. For example, mistyping the
scope
of a fixture produces this:This PR handles a specific of exception type (here
UsageError
for demonstration) so it shows only the exception message instead of the entire traceback. This way we can raise that exception on errors that we know are usage problems and where displaying the entire traceback is not helpful in general. With this PR the error above produces this:Which is definitely nicer.
Questions for discussion:
UsageError
or create a new type of exception? Should it be public so plugins can use it too?Refs: #2293, #3867, #2535, #3332
EDIT: in the end we don't need a new exception, we just have to use
pytest.fail(..., pytrace=False)
instead of general exceptions and make sure we also treatFailed
exceptions during collection.Fixes #2293, Fixes #3867
I will resolve #3332 in a separate PR.