You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be good to have a specific PytestAssertionError(AssertionError) class maybe.
That way it would be possible to distinguish between assert 0 in user code (outside of tests), and e.g. assert 0, "Pattern {!r} not found in {!r}".format(regexp, str(self.value)) (used by ExceptionInfo.match - although that could/should use Failed in the first place probably?
The new class could then also be used from within assertion rewriting, so that "assert 0" there gets turned into PytestAssertionError.
This is just an idea / asking for feedback, but would allow for custom additions to it then, e.g. with regard to terminal representation (highlighting).
The text was updated successfully, but these errors were encountered:
Sounds good for use in pytest assertion helpers like ExceptionInfo.match, but I'd want to be careful about rewriting the exception type.
Many users would have trouble predicting which assertions get re-written, and this would now lead to behaviour differences. Would it be possible to improve the terminal representation without using a custom subclass?
(it would also cause some weird side effects in Hypothesis, where we deduplicate bugs based on the exception type and location - you'd get flaky-test warnings if you ran via pytest and then directly)
Zac-HD
added
the
type: proposal
proposal for a new feature, often to gather opinions or design the API around the new feature
label
Feb 21, 2020
I think it would be good to have a specific
PytestAssertionError(AssertionError)
class maybe.That way it would be possible to distinguish between
assert 0
in user code (outside of tests), and e.g.assert 0, "Pattern {!r} not found in {!r}".format(regexp, str(self.value))
(used byExceptionInfo.match
- although that could/should useFailed
in the first place probably?The new class could then also be used from within assertion rewriting, so that "assert 0" there gets turned into
PytestAssertionError
.This is just an idea / asking for feedback, but would allow for custom additions to it then, e.g. with regard to terminal representation (highlighting).
The text was updated successfully, but these errors were encountered: