Repository navigation
Replies: 1 comment
|
The hook is terminating an xdist worker, rather than reporting an ordinary fixture setup failure. A local reproduction produced a worker-crash report with For a connection failure, catch it in the fixture and report it with import pytest
@pytest.fixture(scope="session")
def connection():
try:
return connect_to_program()
except ConnectionError as exc:
message = str(exc)
# Outside the except block, so the report does not also show exception context.
pytest.fail(message, pytrace=False)Remove the pytest -n 2 --maxfail=1 --tb=shortIn the two-worker reproduction this preserved the connection message and removed both the fixture traceback and the worker-crash reports. Pytest still prints its normal setup-error headings and summary. A session fixture runs separately in each worker, and workers already running can both report errors before This treats the unavailable connection as a setup error, not as a skipped test. If the goal is instead to declare the environment optional, that is a different decision and Reference: https://docs.pytest.org/en/stable/reference/reference.html#pytest.fail These examples and checks were prepared with Codex assistance. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a fixture context created when a session is created, in this context a connection to a specific program instance is made. The connection under certain conditions can fail and throw a ConnectionError exception, in this case I catch it in pytest_exception_interact and call pytest.exit. Then pytest-xdist begin handling exception and outputs the full stack trace, how can I make it output only the connection error message, without the full stack trace and other things?
pytest-8.3.4
pluggy-1.5.0
plugins: xdist-3.6.1
Python 3.13.0 (Windows)
All reactions