Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ UNRELEASED
==========

* Drop support for EOL Python versions: 3.7, 3.8, 3.9.
* Print proper child process exit status.

v1.6.0
======
Expand Down
20 changes: 15 additions & 5 deletions src/pytest_forked/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,23 @@ def runforked():

def report_process_crash(item, result):
from _pytest._code import getfslineno
import signal as signal_module

path, lineno = getfslineno(item)
info = "%s:%s: running the test CRASHED with signal %d" % (
path,
lineno,
result.signal,
)
if result.signal:
sig_name = signal_module.Signals(result.signal).name
info = "%s:%s: running the test CRASHED with signal %d (%s)" % (
path,
lineno,
result.signal,
sig_name,
)
else:
info = "%s:%s: running the test EXITED with status %d" % (
path,
lineno,
result.exitstatus,
)
from _pytest import runner

# pytest >= 4.1
Expand Down
26 changes: 26 additions & 0 deletions testing/test_boxed.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,32 @@ def test_function():
)


@needsfork
def test_crash_message_shows_signal_name(testdir):
p1 = testdir.makepyfile(
"""
import os, signal
def test_function():
os.kill(os.getpid(), signal.SIGTERM)
"""
)
result = testdir.runpytest(p1, "--forked")
result.stdout.fnmatch_lines(["*CRASHED with signal 15 (SIGTERM)*", "*1 failed*"])


@needsfork
def test_crash_message_shows_exit_status(testdir):
p1 = testdir.makepyfile(
"""
import os
def test_function():
os._exit(42)
"""
)
result = testdir.runpytest(p1, "--forked")
result.stdout.fnmatch_lines(["*EXITED with status 42*", "*1 failed*"])


def test_is_not_boxed_by_default(testdir):
config = testdir.parseconfig(testdir.tmpdir)
assert not config.option.forked
2 changes: 1 addition & 1 deletion testing/test_xfail_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_xfail(is_crashing, is_strict, testdir):
reason_string = (
f"reason: The process gets terminated; "
f"pytest-forked reason: "
f"*:*: running the test CRASHED with signal {sig_num:d}"
f"*:*: running the test CRASHED with signal {sig_num:d}*"
)
if expected_lowercase == "xfailed" and PYTEST_GTE_7_2:
short_test_summary += " - " + reason_string
Expand Down