You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is somewhat more complicated than I expected because we have some moving parts to deal with.
We need to make _pytest.main.py catch _pytest.outcomes.Exit explicitly and in that case return a new error code: EXIT_PYTEST_EXIT=6, meaning that an explicit call to pytest.exit(msg) has been made.
Together with the new exit code, I suggest we add a new reason argument to pytest_sessionfinish stating how the session ended. In case of a pytest.exit exception, we would pass its msg argument as reason to pytest_sessionfinish.
pytest-xdist will then need to understand the new exit status 6 and exit gracefully, using the new reason argument in its implementation of pytest_sessionfinish in pytest-xdist/xdist/remote.py.
Any more progress on this one? Just hit it in a separate instance. We have an autouse=True, scope='session' fixture that sets some stuff up before any test runs (in our case, it runs database migrations before our e2e tests). If the setup of the fixture fails, no tests will pass, so we want to bomb early. I just tried changing the exit from sys.exit() to pytest.exit(), and received a similar message to the above indicating a worker process crash.
In the meantime, is there a good workaround to the above? Specifically, is there a good way to gracefully fail the entire test suite when using xdist?
Activity
nicoddemus commentedon Jan 23, 2018
Hi @feuillemorte thanks for looking into this.
This is somewhat more complicated than I expected because we have some moving parts to deal with.
We need to make
_pytest.main.pycatch_pytest.outcomes.Exitexplicitly and in that case return a new error code:EXIT_PYTEST_EXIT=6, meaning that an explicit call topytest.exit(msg)has been made.Together with the new exit code, I suggest we add a new
reasonargument topytest_sessionfinishstating how the session ended. In case of apytest.exitexception, we would pass itsmsgargument asreasontopytest_sessionfinish.pytest-xdistwill then need to understand the new exit status6and exit gracefully, using the newreasonargument in its implementation ofpytest_sessionfinishinpytest-xdist/xdist/remote.py.This is my take on this problem. @RonnyPfannschmidt what do you think?
@feuillemorte I suggest to keep this on hold until we nail down the actual details.
blueyed commentedon Nov 21, 2019
The code is different in this regard already:
pytest/src/_pytest/main.py
Lines 202 to 213 in 8bf343d
(via fc4aa27)
So this might be improved/changed? (came here via #6257)
vkomarov-r7 commentedon Jun 8, 2021
Any more progress on this one? Just hit it in a separate instance. We have an
autouse=True, scope='session'fixture that sets some stuff up before any test runs (in our case, it runs database migrations before our e2e tests). If the setup of the fixture fails, no tests will pass, so we want to bomb early. I just tried changing the exit fromsys.exit()topytest.exit(), and received a similar message to the above indicating a worker process crash.In the meantime, is there a good workaround to the above? Specifically, is there a good way to gracefully fail the entire test suite when using xdist?
nicoddemus commentedon Jun 10, 2021
Hi @vkomarov-r7,
Unfortunately it doesn't seem nobody got the time to sit down and work on this one yet.
I did spend some time now thinking about a possible workaround, but unfortunately couldn't think of any. 😕
I think the outline in #3144 (comment) is what would solve this correctly.