From bedb10010a08919e4652a33579871452f0fdd7eb Mon Sep 17 00:00:00 2001 From: Pankaj Kumar Bind Date: Wed, 13 Aug 2025 21:54:05 +0530 Subject: [PATCH 1/2] test: Add concurrent fixture teardown test for Hypothesis --- tests/hypothesis/test_base.py | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/tests/hypothesis/test_base.py b/tests/hypothesis/test_base.py index 487b05fe..594b7118 100644 --- a/tests/hypothesis/test_base.py +++ b/tests/hypothesis/test_base.py @@ -5,10 +5,11 @@ from __future__ import annotations +import asyncio from textwrap import dedent import pytest -from hypothesis import given, strategies as st +from hypothesis import HealthCheck, given, settings, strategies as st from pytest import Pytester @@ -90,3 +91,44 @@ def test_hypothesis(request, n: int): ) result = pytester.runpytest("--asyncio-mode=auto") result.assert_outcomes(passed=1) + + +def test_hypothesis_concurrent_fixture_teardown(pytester: Pytester): + """ + Tests that Hypothesis-driven tests with concurrent tasks and async fixtures + with teardown logic work correctly. + """ + pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function") + pytester.makepyfile( + dedent( + """\ + import asyncio + import pytest + from hypothesis import given, strategies as st, settings, HealthCheck + + teardown_complete = False + + @pytest.fixture + async def concurrent_fixture(): + global teardown_complete + teardown_complete = False + yield + await asyncio.sleep(0.01) + teardown_complete = True + + async def background_task(): + await asyncio.sleep(0.01) + + @settings(suppress_health_check=[HealthCheck.function_scoped_fixture]) + @given(st.integers()) + @pytest.mark.asyncio + async def test_concurrent_teardown(concurrent_fixture, n): + assert isinstance(n, int) + task = asyncio.create_task(background_task()) + await task + assert not teardown_complete + """ + ) + ) + result = pytester.runpytest("--asyncio-mode=strict") + result.assert_outcomes(passed=1) From e3b6a14c83bc5b14258b60bf29dbddbb449dcd10 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Aug 2025 16:26:12 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/hypothesis/test_base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/hypothesis/test_base.py b/tests/hypothesis/test_base.py index 594b7118..6647b49e 100644 --- a/tests/hypothesis/test_base.py +++ b/tests/hypothesis/test_base.py @@ -5,11 +5,10 @@ from __future__ import annotations -import asyncio from textwrap import dedent import pytest -from hypothesis import HealthCheck, given, settings, strategies as st +from hypothesis import given, strategies as st from pytest import Pytester