Confused by `contains_exactly` message
See original GitHub issueWhen asserting using contains_exactly
I was a little confused by the error message. The fault was mine, I was passing the matcher a list rather than the elements of the list. However, the error message wasn’t immediately clear to me - although I’m not sure the error should be clearer if the API usage was incorrect.
assert_that(degrees, contains_exactly([
> (1, 2), (2, 1), (3, 1), (4, 0)
]))
tests/build/test_importer.py:53:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
value = [(1, 2), (2, 1), (3, 1), (4, 0)], matcher = <precisely.iterable_matchers.ContainsExactlyMatcher object at 0x10f6635f8>
def assert_that(value, matcher):
result = matcher.match(value)
if not result.is_match:
> raise AssertionError("\nExpected: {0}\nbut: {1}".format(matcher.describe(), result.explanation))
E AssertionError:
E Expected: iterable containing in any order:
E * [(1, 2), (2, 1), (3, 1), (4, 0)]
E but: was missing element:
E * [(1, 2), (2, 1), (3, 1), (4, 0)]
E mismatched elements:
E * (1, 2): was (1, 2)
E * (2, 1): was (2, 1)
E * (3, 1): was (3, 1)
E * (4, 0): was (4, 0)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
AssertJ - fluent assertions java library - GitHub Pages
AssertJ is a Java library that provides a rich set of assertions and truly helpful error messages, improves test code readability, and is...
Read more >AbstractIterableAssert - assertj-core 3.23.1 javadoc
Verifies that the actual group contains exactly the given values and nothing else, in order. ... Overrides AssertJ default error message by the...
Read more >Improve the performance of `containsExactly` from quadratic to ...
Hmm, now I'm a tad confused...After doing some digging, it seems as though it may be necessary to iterate through the whole Iterable...
Read more >org.assertj.core.api.IterableAssert.containsExactly java code ...
Best Java code snippets using org.assertj.core.api.IterableAssert.containsExactly (Showing top 20 results out of 900) · Popular methods of IterableAssert.
Read more >AssertJ asserting that List<Long> contains only long[]
containsExactly () expects an array of the same element type as your list, which is Long , not the primitive long .
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So far, I’ve changed the explanations so that your example would be:
I’ve avoided removing the mismatch explanations, even when they’re just a repetition of the repr of the element, since it could be confusing if some elements have the explanation and others don’t. I was thinking of explicitly explaining that the suffix is the mismatch explanation, but I wonder if that would be overly verbose?
I think this can be closed now, but feel free to disagree.