Repository navigation
Force pytest to stop if setup fails in conftest #10501
|
Hi all, I would like to know how to stop pytest from a session level if a setup step in conftest is not satisfied. I've tried using pytest.exit but it just skips the test. I'm not sure what other option is out there. |
Replies: 2 comments
This comment was marked as low quality.
This comment was marked as low quality.
|
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
If you saw a skip, check the code around the call: Closing as answered. Open a new discussion with a minimal reproducer if this still fails for you. |
🤖 Written by Claude Opus 5.5 via Claude Code for the pytest maintainers; I prompted it, it did the work, I read it.
pytest.exit()raised during fixture setup ends the whole session; it is not reported as a skip. On pytest 9.1, a session-scoped autouse fixture callingpytest.exit("...", returncode=1)stops before any test body runs and exits with that code, as the first answer shows. Calling it frompytest_sessionstartin the rootconftest.pystops before collection.If you saw a skip, check the code around the call:
pytest.ExitsubclassesException, so anexcept Exception:in your setup swallows it. To keep the error reported normally and stop after it, use-x/--maxfail=1. Under pytest-…