对AssertionError重复测试

问题描述 投票:1回答:1

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

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

python python-3.x pytest
1个回答
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.')
© www.soinside.com 2019 - 2024. All rights reserved.