There’s a new release of pytest-check. Version 2.6.0.
This is a cool contribution from the community.
The problem
In July, bluenote10 reported that check.raises()
doesn’t behave like pytest.raises()
in that the AssertionError
returned from check.raises()
doesn’t have a queryable value
.
Example of pytest.raises()
:
with pytest.raises(Exception) as e:
do_something()
assert str(e.value) == "<expected error message>"
We’d like check.raises()
to act similarly:
with check.raises(Exception) as e:
do_something()
assert str(e.value) == "<expected error message>"
But that didn’t work prior to 2.6.0. The issue was that the value returned from check.raises()
didn’t have any .value
atribute.
The fix
This is fixed in 2.6.0, thanks to shairoth12.
The fix is elegant, and seems simple, now that I see it. Just make sure the return value has a value
property and upon exiting the context manager, assign self.value = exc_val
. Nice. See the PR #188 if you’d like to see the change.
Shai included implementation, elegant test code, updates to the README, and updates to the changelog
I appreciate the community effort.
The release
This is the only change in the release. However, since it kinda changes the interface in that the functionality of a return value of a method is now different, I figured a minor version bump wouldn’t hurt.
Thus 2.6.0.
Enjoy.