Martin Panter added the comment:
Looking at Gregory and Robert’s “matchers” link, which also covers
“assertThat”, it seems to provide a library of matcher assertion objects. E.g.
instead of this TestCase-coupled code:
self.assertEquals(something, "expected value")
you would write
from testtools.matchers import Equals
self.assertThat(something, Equals("expected value"))
Implementing a custom matcher (say HasAttr for Serhiy’s first use case) seems
to involve creating the HasAttr class with a match() method, and maybe another
HasAttrMismatch class (though maybe you could get away with just a shared
generic mismatch class?).
It seems to me that if you ignore the vaguely-documented
TestCase.failureException attribute, you can fairly easily decouple the
existing methods from a TestCase instance:
def assert_equal(first, second, msg=None):
# Implementation could be copied independently of any test state
TestCase().assertEqual(first, second, msg)
The matcher scheme would be more flexible though, because you can compose
matcher objects.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19645>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com