Reputation: 1592
I have few web service related test which sends http requests and the response is verified by py.test test cases. I usually get 1 or 2 failures out of 50 tests which are fails due to intermittent slow web server response gathering or due to network.
Is there a way I can re-run or add number of retires to a py.test test case before actually marking it as a Failed one ? Something like run a test 3 times before marking it as failure and moving to the next one, If test passes in any attempt(1 or 2 or in 3) mark it as passed ?
Upvotes: 4
Views: 5062
Reputation: 467
You should check the documentation of pytest, you can either rerun faileds only, or rerun by starting on fails.
pytest --lf
https://docs.pytest.org/en/7.1.x/how-to/cache.html
Upvotes: 0
Reputation: 550
flaky describes a possible solution to your problem: https://github.com/box/flaky -- It allows for re-running failed tests once as a default, or up to n times.
You could also try using Looponfail: https://pytest.org/latest/xdist.html. Although it's technically meant to allow for altering a file associated with the failed test, it'll still pause the test you're running after a failure.
Hope this helps.
Upvotes: 4