Skip to content

Commit c8f65f5

Browse files
committed
Refine tests
1 parent 2530e37 commit c8f65f5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/test_invalid_holder_access.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import gc
44
import multiprocessing
5+
import signal
6+
import sys
57
import weakref
68

79
import pytest
@@ -14,8 +16,10 @@
1416

1517

1618
try:
19+
import multiprocessing
20+
1721
spawn_context = multiprocessing.get_context("spawn")
18-
except ValueError:
22+
except (ImportError, ValueError):
1923
spawn_context = None
2024

2125

@@ -51,9 +55,9 @@ def manual_new_target():
5155
# The C++ compiler initializes container correctly.
5256
assert vec.size() == 0
5357
else:
54-
raise SystemError(
55-
"Segmentation Fault: The C++ compiler initializes container incorrectly."
56-
)
58+
# The program is not supposed to reach here. It will abort with
59+
# SIGSEGV on `vec.is_empty()`.
60+
sys.exit(signal.SIGSEGV) # manually trigger SIGSEGV if not raised
5761
vec.append(1)
5862
vec.append(2)
5963
vec.append(3)
@@ -64,13 +68,18 @@ def manual_new_target():
6468
# guaranteed to work everywhere. It is marked as non-strict xfail.
6569
@pytest.mark.xfail(reason=XFAIL_REASON, raises=SystemError, strict=False)
6670
@pytest.mark.skipif(spawn_context is None, reason="spawn context not available")
71+
@pytest.mark.skipif(
72+
sys.platform.startswith("emscripten"),
73+
reason="Requires multiprocessing",
74+
)
6775
def test_manual_new():
6876
process = spawn_context.Process(
6977
target=manual_new_target,
7078
name="manual_new_target",
7179
)
7280
process.start()
7381
process.join()
82+
assert abs(process.exitcode) in (0, signal.SIGSEGV, signal.SIGABRT)
7483
if process.exitcode != 0:
7584
raise SystemError(
7685
"Segmentation Fault: The C++ compiler initializes container incorrectly."

0 commit comments

Comments
 (0)