2 ms·
That is better, but doesn't check for incorrectly repeated elements: result = ["a", "b", "b"] assert set(result) == {"a", "b"} In fact that is the fir
by quietbritishjim 6y ago
That is better, but doesn't check for incorrectly repeated elements:
result = ["a", "b", "b"]
assert set(result) == {"a", "b"}
In fact that is the first main motivating failure case discussed in the readme. But actually that's simple enough to deal with too:
from collections import Counter
assert Counter(result) = {"a": 1, "b": 1}
But would be trickier for mutable / unhashable types (not sure if "precisely" can deal with those).
- mwilliamson 6y agoYup, precisely should work fine with mutable / unhashable types -- it just relies on equality to check the elements in an iterable. More specifically, writing: contains_exactly("a", "b") is equivalent to: contains_exactly(equal_to("a"), equal_to("b"))