Repeat a test upon an AssertionError

廉价感情. 提交于 2019-12-11 07:08:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!