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
is_not/not_ will not invert raises() matcher #111
Comments
I'm not sure I understand the issue here - it all seems to be working as expected to me: assert_that(calling(int).with_args('q'), raises(ValueError)) # Passes, since a ValueError is raised
assert_that(calling(int).with_args(1), not_(raises(ValueError))) # Passes, since a ValueError is not raised
assert_that(calling(int).with_args('q'), not_(raises(ValueError))) . # Fails, since a ValueError is raised
assert_that(calling(int).with_args(1), raises(ValueError)) # Fails, since a ValueError is not raised |
So the issues is that
where as I am expecting something like
In more human terms I am asserting that ValueError should not be raised but is being raised @offbyone ... any thoughts appreciated. |
I think you're right about what we should see there. |
Okey dokey, I'll look into it. |
The problem here is that Matchers in general use the The standard way to get a test to fail if an exception is raised is of course just a bare call: int('q') |
If it's not practical, it's not practical. I agree with the original requester about what we might hope to see here, but you're right; describing success is tricky. I haven't been in the code in a while, so I'm not completely sure, but maybe we could leverage the self-describing aspect of it. I'm definitely not in favor of a radical rearchitecture areound this, though :) |
In fact, I think I have a simple and relatively backward compatible solution for this.
The downside of this is that any custom matchers not inheriting from Thoughts? Happy to run with either of these if you give me the go ahead. |
I've tried this out on a branch here. Needs docs before PRing. but you can see what I'm getting at. |
Is this still a valid issue or did you just forget to close this report? |
Fixed - should be part of the forthcoming 2.0 release. |
As far as I can tell is_not should invert any matcher. Recently had a situation where I need an to invert a raises and it did not work as expected. In some ways inverting raises is an antipattern but in my case alternatives are uglier. Below is a simplified example of the issue.
Please advise if this is a bug? or is there an alternative way to address this.
Content
example.py
Output:
Expected: test passing
The text was updated successfully, but these errors were encountered: