我正在编写单元测试,并引发了许多类似的错误消息,以至于代码看起来非常混乱.
大概是这样的:
# Test that compare_pass1 is downstream to secondary_pass1
self.assertTrue(
all(
task in all_downstream_task_for_secondary_pass1_task
for task in {compare_pass1}
),
f'One of {compare_pass1} not found in downstream to {secondary_pass1_task task}',
)
# Check that primary_pass1 is upstream to secondary_pass1
self.assertTrue(
all(
task in all_upstream_task_for_secondary_pass1_task
for task in {primary_pass1_task}
),
f'One of {primary_pass1_task} not found in upstream to {secondary_pass1_task} task',
)
# Check that secondary_pass1 is upstream to compare_pass1
self.assertTrue(
all(
task in all_upstream_task_for_compare_pass1_task
for task in {secondary_pass1_task}
),
f'one of {secondary_pass1_task} not found in upstream to {compare_pass1_task} task',
)
我所关注的是当单元测试失败时抛出的错误消息,虽然它们不完全相同,但消息是相似的.
是否存在创建函数并在抛出错误消息时调用函数的约定?