ENH: testing: argument err_msg of assertion functions can be any object#24877
Merged
rgommers merged 6 commits intonumpy:mainfrom Oct 14, 2023
Merged
ENH: testing: argument err_msg of assertion functions can be any object#24877rgommers merged 6 commits intonumpy:mainfrom
err_msg of assertion functions can be any object#24877rgommers merged 6 commits intonumpy:mainfrom
Conversation
This lets you pass any object, similar to how you would do for a native Python assert a == b, msg
mdhaber
commented
Oct 7, 2023
Member
|
Cool thanks |
tylerjereddy
reviewed
Oct 9, 2023
Contributor
tylerjereddy
left a comment
There was a problem hiding this comment.
In case it helps, this test fails on main and passes here:
--- a/numpy/testing/tests/test_utils.py
+++ b/numpy/testing/tests/test_utils.py
@@ -1648,3 +1648,12 @@ def __del__(self):
finally:
# make sure that we stop creating reference cycles
ReferenceCycleInDel.make_cycle = False
+
+@pytest.mark.parametrize("assert_func", [
+ assert_equal,
+ assert_allclose,
+ assert_array_equal])
+def test_err_msg_obj(assert_func):
+ a = np.zeros(10)
+ with pytest.raises(AssertionError):
+ assert_func(a, a + 7, err_msg=1)
Contributor
Author
|
Thanks @tylerjereddy. I'd be happy to add that and/or the one in #24877 (comment) (Details) as a unit test if desired. (I would have done that if I were starting from scratch, but It looked like the original PR was ready to merge except for a CI glitch, so I didn't think I should add more code to review if it wasn't considered necessary.) |
BvB93
added a commit
to BvB93/numpy
that referenced
this pull request
Dec 21, 2023
…itrary objects Xref numpy#24877
BvB93
added a commit
to BvB93/numpy
that referenced
this pull request
Dec 21, 2023
…itrary objects Xref numpy#24877
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes gh-17011
gh-17011 proposed calling
strautomatically on theerr_msgargument of assertion functions to make them more tolerant and mimic the behavior of Pythonassertstatements.It looks like the PR was inactive, so I took the liberty of merging main (to preserve @asmeurer 's) commits, making the suggested change , and making a patch to ensure that this works for all assertion functions that accept
err_msg.Details
For local testing:I could add this as a unit test, if desired.
@mattip it looks like you may have been willing to review the original PR. Would you be able to take a look at this one?