pytest-dev / pytest-rerunfailures

a pytest plugin that re-runs failed tests up to -n times to eliminate flakey failures
Other
369 stars 82 forks source link

Rerun all tests if any test fails #228

Open dron4ik86 opened 1 year ago

dron4ik86 commented 1 year ago

Hi, I've encountered a situation with my test suite where the tests are interdependent, meaning the outcome of one test can affect subsequent tests. I understand that it's typically best practice to isolate tests, but due to the nature of my test suite, isolating each test is not feasible. When I use the pytest-rerunfailures plugin, it only reruns the specific test that fails. In my case, however, if one test fails, I need all tests to be rerun because the failed test could influence the outcomes of the others. Therefore, I'd like to propose a new feature or option for the plugin: an option to rerun the entire test suite (or a specified group of tests) if any test fails. For now, my solution to solve this issue is this:

max_retries = 5
retries = 0
while retries < max_retries:
    result = pytest.main(["tests/test_my_tests.py"])
    if result == 0:
        print("Tests passed!")
        break
    else:
        print("Tests failed, rerunning...")
        retries += 1

This feature would provide value for test suites where tests are interdependent and the failure of one test may invalidate the outcomes of the others. I believe this could be a useful addition to the plugin's functionality.

Thank you for considering my proposal.