-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
pytest plugin re-runs all tests if a crash occurs inside a pytest_runtestloop
hook when using pytest-xdist
#24846
Comments
pytest_runtestloop
hookpytest_runtestloop
hook when using pytest-xdist
yes i do, sorry i didn't notice that when i was creating my repro, but it prints the following error during collection:
although the issue still occurs when i update the from pytest import Session, hookimpl
@hookimpl(tryfirst=True)
def pytest_runtestloop(session: Session):
if not session.config.option.collectonly:
raise Exception(f'failed running tests with args: {session.config.args}')
output from collection
output from run
|
Thank you for those details- so it is interesting because the process ID at both exceptions is the main process thread, so it is not being hit in each worker or rerun at that level (from what I can tell). My next guess is maybe workers are rerun by the main process if exceptions occur. Can you try adding this argument and see if that changes anything? |
same result Details
no worries, thanks for taking the time to investigate
i'm on windows 11, let me know if you need any more details and i will try to provide them |
Type: Bug
Behaviour
when a crash occurs inside a
pytest_runtestloop
hook while the xdist plugin is active, it will attempt to re-run all tests.Steps to reproduce:
create the following files:
use the test explorer to run the parametrized test:

check the test results tab. notice there are two separate crashes:
the first crash is expected, but the second one is not. it seems to be re-running pytest after the crash with the project root as the only argument, which tells pytest to run all tests in the project.
Extension version: 2025.1.2025022102
VS Code version: Code 1.97.2 (e54c774e0add60467559eb0d1e229c6452cf8447, 2025-02-12T23:20:35.343Z)
OS version: Windows_NT x64 10.0.22621
Modes:
The text was updated successfully, but these errors were encountered: