How to immediately restart the test in case of a crash?

Viewed 12

I have a test that may crash if the server is currently unavailable.

Can you tell me how I can immediately restart the same test in case it crashes (Without waiting for the completion of other tests)? And to recognize it as really failed only in case of a second failure.

I saw a solution using the pytest-rerunfailures library, but it needs to be additionally installed, and this does not quite suit me

Also, I present a solution with the try-except construction, but it seems to me that there should be a more convenient solution

1 Answers

With the help of try-except I present the solution like this:

def test_first():
    try:
        assert 1 == 0 # The main part of the function
    except:
        assert 1 == 0 # In case of failure, just repeat the same code
Related