Skip to content

test: Add concurrent fixture teardown test for Hypothesis #1190

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 41 additions & 0 deletions tests/hypothesis/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,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)
Loading