对AssertionError重复测试

时间:2018-06-18 11:15:27

标签: python python-3.x pytest

模块pytest-repeat可用于重复执行pytest N次(整个测试套件)。

但是,我想在AssertionError上再次重新运行该特定测试,而不是运行整个套装。那么,我如何捕获AssertionError并以编程方式调用相同的测试函数?

1 个答案:

答案 0 :(得分:1)

flaky package提供@flaky装饰器。来自文档:

@flaky(max_runs=3, min_passes=2)
def test_something_that_usually_passes(self):
    """This test must pass twice, and it can be run up to three times."""
    value_to_double = 21
    result = get_result_from_flaky_doubler(value_to_double)
    self.assertEqual(result, value_to_double * 2, 'Result doubled incorrectly.')