question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Confused by `contains_exactly` message

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwilliamsoncommented, Jan 31, 2018

So far, I’ve changed the explanations so that your example would be:

Expected: iterable containing 1 element:
  * [(1, 2), (2, 1), (3, 1), (4, 0)]
but: was missing element:
  * [(1, 2), (2, 1), (3, 1), (4, 0)]
These elements were in the iterable, but did not match:
  * (1, 2): was (1, 2)
  * (2, 1): was (2, 1)
  * (3, 1): was (3, 1)
  * (4, 0): was (4, 0)

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?

Expected: iterable containing 1 element:
  * [(1, 2), (2, 1), (3, 1), (4, 0)]
but: was missing element:
  * [(1, 2), (2, 1), (3, 1), (4, 0)]
These elements were in the iterable, but did not match:
  * (1, 2)
    * mismatch reason: was (1, 2)
  * (2, 1)
    * mismatch reason: was (2, 1)
  * (3, 1)
    * mismatch reason: was (3, 1)
  * (4, 0)
    * mismatch reason: was (4, 0)
0reactions
mwilliamsoncommented, Feb 14, 2018

I think this can be closed now, but feel free to disagree.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found