python自带assert可实现简单断言,但遇到复杂断言assert就不能支持了。而hamcrest能够很好的支持复杂断言,下面举例说明。
GitHub地址:https://github.com/hamcrest/PyHamcrest
示例
from hamcrest import *
def test_hamcrest():
the_string = 'Hello Hamcrest'
my_string = 'Hello Hamcrest'
assert_that(the_string, equal_to(my_string)<