Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test tweaks #4012

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
20 changes: 13 additions & 7 deletions hypothesis-python/tests/nocover/test_recursive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at https://mozilla.org/MPL/2.0/.

import gc
import sys
import threading
import warnings

import pytest

from hypothesis import HealthCheck, given, settings, strategies as st

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


@flaky(min_passes=1, max_runs=2)
def test_gc_hooks_do_not_cause_unraisable_recursionerror():
def test_gc_hooks_do_not_cause_unraisable_recursionerror(testdir):
# We were concerned in #3979 that we might see bad results from a RecursionError
# inside the GC hook, if the stack was already deep and someone (e.g. Pytest)
# had installed a sys.unraisablehook which raises that later.
Expand All @@ -197,6 +194,14 @@ def test_gc_hooks_do_not_cause_unraisable_recursionerror():
# constant. Regardless, if the test passes just once that's sufficient proof that
# it's not the GC (or accounting of it) that is at fault. Note, I haven't actually
# seen it fail/flake, but I believe it could happen in principle.
#
# What we *have* seen on CI with xdist is flaky segmentation faults. Hence, the
# test is executed in a subprocess.
script = """
import gc
import pytest

from hypothesis import given, strategies as st

# The number of cycles sufficient to reliably trigger GC, experimentally found
# to be a few hundred on CPython. Multiply by 10 for safety margin.
Expand Down Expand Up @@ -240,7 +245,7 @@ def gen_cycles_at_depth(depth, *, gc_disable):
probe_depth()

@given(st.booleans())
def inner_test(_):
def test_gc_hooks_recursive(_):
max_depth = probe_depth()

# Lower the limit to where we can successfully generate cycles
Expand All @@ -265,5 +270,6 @@ def inner_test(_):
gen_cycles_at_depth(max_depth, gc_disable=False)
with pytest.raises(RecursionError):
gen_cycles_at_depth(max_depth + 1, gc_disable=False)

inner_test()
"""
testdir.makepyfile(script)
testdir.runpytest_subprocess().assert_outcomes(passed=1)
Loading