Skip to content

Commit 3cff24c

Browse files
committed
Move gc-hook on recursion test to subprocess
1 parent 9944b59 commit 3cff24c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

hypothesis-python/tests/nocover/test_recursive.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

11-
import gc
1211
import sys
1312
import threading
1413
import warnings
1514

16-
import pytest
17-
1815
from hypothesis import HealthCheck, given, settings, strategies as st
1916

2017
from tests.common.debug import find_any, minimal
@@ -188,7 +185,7 @@ def test_self_ref_regression(_):
188185

189186

190187
@flaky(min_passes=1, max_runs=2)
191-
def test_gc_hooks_do_not_cause_unraisable_recursionerror():
188+
def test_gc_hooks_do_not_cause_unraisable_recursionerror(testdir):
192189
# We were concerned in #3979 that we might see bad results from a RecursionError
193190
# inside the GC hook, if the stack was already deep and someone (e.g. Pytest)
194191
# had installed a sys.unraisablehook which raises that later.
@@ -197,6 +194,14 @@ def test_gc_hooks_do_not_cause_unraisable_recursionerror():
197194
# constant. Regardless, if the test passes just once that's sufficient proof that
198195
# it's not the GC (or accounting of it) that is at fault. Note, I haven't actually
199196
# seen it fail/flake, but I believe it could happen in principle.
197+
#
198+
# What we *have* seen on CI with xdist is flaky segmentation faults. Hence, the
199+
# test is executed in a subprocess.
200+
script = """
201+
import gc
202+
import pytest
203+
204+
from hypothesis import given, strategies as st
200205
201206
# The number of cycles sufficient to reliably trigger GC, experimentally found
202207
# to be a few hundred on CPython. Multiply by 10 for safety margin.
@@ -240,7 +245,7 @@ def gen_cycles_at_depth(depth, *, gc_disable):
240245
probe_depth()
241246
242247
@given(st.booleans())
243-
def inner_test(_):
248+
def test_gc_hooks_recursive(_):
244249
max_depth = probe_depth()
245250
246251
# Lower the limit to where we can successfully generate cycles
@@ -265,5 +270,6 @@ def inner_test(_):
265270
gen_cycles_at_depth(max_depth, gc_disable=False)
266271
with pytest.raises(RecursionError):
267272
gen_cycles_at_depth(max_depth + 1, gc_disable=False)
268-
269-
inner_test()
273+
"""
274+
testdir.makepyfile(script)
275+
testdir.runpytest_subprocess().assert_outcomes(passed=1)

0 commit comments

Comments
 (0)