Closed jml closed 8 years ago
Given this code:
from testtools import TestCase from testtools.matchers import Equals, MatchesListwise class FooTests(TestCase): def test_foo(self): self.assertThat([1], MatchesListwise([Equals(1), Equals(2)])) def test_suite(): return FooTests('test_foo')
On master, we would get this result:
$ python -m testtools.run example.test_suite Tests running... ====================================================================== FAIL: example.FooTests.test_foo ---------------------------------------------------------------------- Traceback (most recent call last): File "example.py", line 8, in test_foo self.assertThat([1], MatchesListwise([Equals(1), Equals(2)])) File "testtools/testcase.py", line 435, in assertThat raise mismatch_error testtools.matchers._impl.MismatchError: Differences: [ len([1]) != 2: Length mismatch ] Ran 1 test in 0.002s FAILED (failures=1)
This result doesn't communicate anything about the object being matched.
This patch changes MatchesListwise to use HasLength for its length matching, which turns the error into:
MatchesListwise
HasLength
$ python -m testtools.run example.test_suite Tests running... ====================================================================== FAIL: example.FooTests.test_foo ---------------------------------------------------------------------- Traceback (most recent call last): File "example.py", line 8, in test_foo self.assertThat([1], MatchesListwise([Equals(1), Equals(2)])) File "testtools/testcase.py", line 435, in assertThat raise mismatch_error testtools.matchers._impl.MismatchError: Differences: [ len([1]) != 2: Length mismatch ] Ran 1 test in 0.001s FAILED (failures=1)
Note that the traceback now includes the item being matched ([1]).
[1]
Merging w/ timeout rule.
Given this code:
On master, we would get this result:
This result doesn't communicate anything about the object being matched.
This patch changes
MatchesListwise
to useHasLength
for its length matching, which turns the error into:Note that the traceback now includes the item being matched (
[1]
).