Skip to content Skip to sidebar Skip to footer

Repeat A Test Upon An AssertionError

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 specif

Solution 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.')

Post a Comment for "Repeat A Test Upon An AssertionError"