Skip to content

Warn when pytest_cmdline_main hook raises SystemExit - #15534

Open
hrushiraj19 wants to merge 1 commit into
pytest-dev:mainfrom
hrushiraj19:warn-cmdline-main-systemexit
Open

hrushiraj19 wants to merge 1 commit into
pytest-dev:mainfrom
hrushiraj19:warn-cmdline-main-systemexit

Conversation

@hrushiraj19

Copy link
Copy Markdown

Summary

Per #8986, pytest's own pytest_cmdline_main implementations return an ExitCode or int rather than raising SystemExit. When a third-party plugin raises SystemExit directly in pytest_cmdline_main, it bypasses pytest.main()'s normal return path without any warning.

This PR:

  • Catches SystemExit around config.hook.pytest_cmdline_main(config=config) in _pytest.config._main(), emits a PytestConfigWarning, and re-raises SystemExit to preserve existing exit-code behavior.
  • Adds test_cmdline_main_systemexit_warning in testing/test_main.py.
  • Adds a changelog fragment in changelog/8986.bugfix.rst.

Fixes #8986

Emit a PytestConfigWarning when a plugin raises SystemExit inside
pytest_cmdline_main instead of returning an ExitCode or int, then
re-raise SystemExit so existing exit-code behavior is preserved.

Fixes pytest-dev#8986
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

warn when the cmdline_main hook raises systemexit

1 participant