New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop testing a file on first fail #9515
Comments
As a workaround you can probably have a fixture that stores the module name on first failure to a list and raise skip for rest of the files of the same module name. It also will not work on xdist since the list is at module level and you might need to store it somewhere reliable for parallel processing.
import pytest
skip_modules = []
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
rep = outcome.get_result()
setattr(item, "rep_" + rep.when, rep)
@pytest.fixture(autouse=True)
def skip_file_on_fail(request):
mod_name = request.module.__name__
if mod_name in skip_modules:
pytest.skip(f"Skipping rest of tests in {mod_name}")
outcome = yield
if request.node.rep_call.failed:
skip_modules.append(request.module.__name__) |
Not sure if this should be closed, @Zac-HD - it seems like an useful proposal at first sight. |
Worth a mention in the doc. |
What's the problem this feature will solve?
This allows me to gather all failed files quicker, I don't need to know whether the remaining tests passed in this file.
Describe the solution you'd like
This will be equivalent to the
-x
option, but on a per-file basis. That is, pytest stops testing this file if it has one failed test.This can save time when running on clouds like Github Action, if it fails fast, then I'll be charged less, knowing I have to re-run them.
Alternative Solutions
I'm not sure which plugin can solve this problem.
Additional context
The text was updated successfully, but these errors were encountered: