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

Use a specific PytestAssertionError class? #6777

Open
blueyed opened this issue Feb 20, 2020 · 1 comment
Open

Use a specific PytestAssertionError class? #6777

blueyed opened this issue Feb 20, 2020 · 1 comment
Labels
type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature

Comments

@blueyed
Copy link
Contributor

blueyed commented Feb 20, 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 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).

@Zac-HD
Copy link
Member

Zac-HD commented Feb 21, 2020

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: proposal proposal for a new feature, often to gather opinions or design the API around the new feature
Projects
None yet
Development

No branches or pull requests

2 participants