8
8
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
9
9
# obtain one at https://mozilla.org/MPL/2.0/.
10
10
11
- import gc
12
11
import sys
13
12
import threading
14
13
import warnings
15
14
16
- import pytest
17
-
18
15
from hypothesis import HealthCheck , given , settings , strategies as st
19
16
20
17
from tests .common .debug import find_any , minimal
@@ -188,7 +185,7 @@ def test_self_ref_regression(_):
188
185
189
186
190
187
@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 ):
192
189
# We were concerned in #3979 that we might see bad results from a RecursionError
193
190
# inside the GC hook, if the stack was already deep and someone (e.g. Pytest)
194
191
# had installed a sys.unraisablehook which raises that later.
@@ -197,6 +194,14 @@ def test_gc_hooks_do_not_cause_unraisable_recursionerror():
197
194
# constant. Regardless, if the test passes just once that's sufficient proof that
198
195
# it's not the GC (or accounting of it) that is at fault. Note, I haven't actually
199
196
# 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
200
205
201
206
# The number of cycles sufficient to reliably trigger GC, experimentally found
202
207
# 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):
240
245
probe_depth()
241
246
242
247
@given(st.booleans())
243
- def inner_test (_ ):
248
+ def test_gc_hooks_recursive (_):
244
249
max_depth = probe_depth()
245
250
246
251
# Lower the limit to where we can successfully generate cycles
@@ -265,5 +270,6 @@ def inner_test(_):
265
270
gen_cycles_at_depth(max_depth, gc_disable=False)
266
271
with pytest.raises(RecursionError):
267
272
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