-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add a "pytest.maybe_raises" #10654
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
Comments
Use null content |
On the contrary:
|
The api contract is simply unacceptable, there was a lengthy disc before Im happy to fix the typing, i will absolutely refuse api shitstains like magic boolean flags that change behaviour so strongly it should have a different name to begin with |
Sorry, couldn't find the previous issue, mind linking for posterity? I found #8646 somewhat related. I'm not sure I follow re: "magic boolean flags". There's no current semantical meaning to
I do understand that aversion to (1), as But whatever it is, it's good to record the decision. And at the very least, we should address that typing issue. |
One thing is absolutely in stone, raises itself is only for ensuring exceptions happen Opening the api of raises itself up to not doing that is horrendous api Design that trades a small convenience for a niche usecase with a unacceptable "forever cost" The context manager that just does nothing is already null context in the stdlib |
Additionally the context manager that ignores certain exceptions is also in the stdlib, so there currently really seems to be no reason to expand the api, Only a reason to fix the type information |
This is the result of a fairly long and involved migration, because when that did do something there were three wildly different and common assumptions about what it meant. Unfortunately we're not going to accept this feature request; you can use |
That's in fact what I did, which made me think that could be valuable in pytest, which resulted in this proposal, but obviously there's a high bar for including something in a core library (given that we're then "stuck" maintaining it) and I'm fine not including it. Related decision in another test helper library: |
What's the problem this feature will solve?
Sometimes it's convenient to parameterize both raising and non-raising case, e.g.
With pytest as it stands, I'd have to do something more akward like:
or if I prefer not to repeat the call:
Describe the solution you'd like
Here's the snippet from my project's test helper module:
Alternative Solutions
The code above is from my project code, so it's possible to complement pytest rather than add to it. However, since I found this to be a useful pattern, I'd like to propose adding it to pytest.
We can make
pytest.raises
accept an optional exception and return aContextManager[Optional[pytest.ExceptionInfo]]
. As-is it'd be a breaking change, but we could perhaps do this as an@override
.The text was updated successfully, but these errors were encountered: