我正在使用 PyHamcrest,但我认为这个问题与语言无关。
我想转:
assert_that(actual0, matcher0)
assert_that(actual1, matcher1)
成一个断言,这样如果两个断言都失败,错误消息就会这样说。这可以在 Hamcrest(或其他一些包/模块)中完成吗?
在 Python 中,我实现了:
def assert_all(*assertions):
    assertion_failed = False
    assertion_message = []
    for (actual, matcher) in assertions:
        try:
            hamcrest.assert_that(actual, matcher)
        except AssertionError as e:
            assertion_failed = True
            assertion_message.append(e.message)
    if assertion_failed:
        raise AssertionError(''.join(assertion_message))
所以我的测试会调用:
assert_all(
    (actual0, matcher0),
    (actual1, matcher1))
但我想知道是否已经有这样的实现。