Skip to content

Improve crash message: distinguish exit vs signal#98

Merged
nicoddemus merged 3 commits intopytest-dev:masterfrom
kalvdans:improve-crash-message
Mar 2, 2026
Merged

Improve crash message: distinguish exit vs signal#98
nicoddemus merged 3 commits intopytest-dev:masterfrom
kalvdans:improve-crash-message

Conversation

@kalvdans
Copy link
Contributor

When a forked test process exits with a non-zero exit code (signal == 0), the message previously said "CRASHED with signal 0" which is misleading — signal 0 is not a real signal and the process was not killed by one.

Now:

  • Non-signal exit: "EXITED with status "
  • Signal kill: "CRASHED with signal ()" e.g. "signal 11 (SIGSEGV)"

signal.Signals() is called without a try/except because result.signal comes from os.WTERMSIG(), which extracts the signal from the kernel's wait status — the kernel can only kill a process with a valid signal number.

Note: sys.exit() is caught by pytest as SystemExit and does not trigger report_process_crash; os._exit() bypasses the marshal pipe and does.

When a forked test process exits with a non-zero exit code (signal == 0),
the message previously said "CRASHED with signal 0" which is misleading —
signal 0 is not a real signal and the process was not killed by one.

Now:
- Non-signal exit: "EXITED with status <N>"
- Signal kill:     "CRASHED with signal <N> (<NAME>)" e.g. "signal 11 (SIGSEGV)"

signal.Signals() is called without a try/except because result.signal comes
from os.WTERMSIG(), which extracts the signal from the kernel's wait status —
the kernel can only kill a process with a valid signal number.

Note: sys.exit() is caught by pytest as SystemExit and does not trigger
report_process_crash; os._exit() bypasses the marshal pipe and does.
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Could you please also add a changelog entry? Thanks!

@kalvdans
Copy link
Contributor Author

Could you please also add a changelog entry? Thanks!

Thanks for the reivew! I added an item to the changelog.

@nicoddemus
Copy link
Member

Hmm the tests are failing, could you take a look? Thanks

The reason_string pattern lacked a trailing wildcard, so it failed to
match after the crash message started including the signal name
(e.g. "signal 15 (SIGTERM)").

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kalvdans
Copy link
Contributor Author

Tests fixed 👍 (They run successfully locally in on MacOS on Python 3.13)

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I will leave it open for a few days to give @RonnyPfannschmidt a chance to review, otherwise I will merge/squash it then.

@nicoddemus nicoddemus merged commit f910a11 into pytest-dev:master Mar 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants