问题
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 ?
回答1:
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.
来源:https://stackoverflow.com/questions/33894691/how-to-re-run-failed-test-and-set-re-tries-for-python3-py-test