问题
There is the module pytest-repeat which can be used to repeat the execution of pytest N times (the whole test suite).
However, I want to, upon an AssertionError, re-run that specific test again, instead of running the whole suit. So, how can I capture the AssertionError and programmatically call the same test function?
回答1:
The flaky package provides a @flaky decorator. From the documentation:
@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.')
来源:https://stackoverflow.com/questions/50908236/repeat-a-test-upon-an-assertionerror