Reputation:
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?
Upvotes: 1
Views: 320
Reputation: 10355
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.')
Upvotes: 1