有一个模块pytest-repeat可以用来重复执行pytest N次(整个测试套件)。
但是,我想在AssertionError上再次重新运行该特定测试,而不是运行整个套装。那么,我如何捕获AssertionError并以编程方式调用相同的测试函数?
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.')