Skip to content

Fully support async tests and fixtures#485

Merged
MatthewMckee4 merged 9 commits intomainfrom
async-test-support
Feb 17, 2026
Merged

Fully support async tests and fixtures#485
MatthewMckee4 merged 9 commits intomainfrom
async-test-support

Conversation

@MatthewMckee4
Copy link
Member

Summary

  • Add asyncio.run() support so async def test_*() functions are properly awaited instead of silently passing
  • Handle async fixtures (non-generator) by wrapping their return coroutine with asyncio.run()
  • Handle async generator fixtures by using __anext__() + asyncio.run() for both setup and teardown

Closes #484

Test plan

  • test_async_function — basic async test that passes
  • test_async_function_with_assertion_error — async test that fails with assertion
  • test_async_fixture — async non-generator fixture with async test
  • test_async_generator_fixture — async generator fixture with setup/teardown verification
  • test_async_test_with_sync_fixture — async test consuming a sync fixture
  • test_sync_test_with_async_fixture — sync test consuming an async fixture
  • Full test suite (637 tests pass)
  • uvx prek run -a passes

🤖 Generated with Claude Code

Async test functions, async fixtures, and async generator fixtures were
silently passing without executing because coroutines were never awaited.
This adds `asyncio.run()` integration at each call site so async Python
code is properly executed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MatthewMckee4 MatthewMckee4 added test-running Related to running tests with karva extensions/fixtures Related to fixtures rust Pull requests that update rust code labels Feb 16, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 16, 2026

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 1 untouched benchmark


Comparing async-test-support (56fd2c1) with main (631b238)

Open in CodSpeed

@MatthewMckee4 MatthewMckee4 removed the rust Pull requests that update rust code label Feb 16, 2026
Patch hypothesis.inner_test with a sync wrapper that uses asyncio.run()
so that @given can call async test functions without raising InvalidArgument.

- Add patch_async_test_function() helper in utils.rs
- Use it in execute_test_variant to detect and patch wrapped async tests
- Extract test venv deps into requirements.txt (pytest + hypothesis)
- Add integration test for @given + async def
Set __signature__ directly on the closure so inspect.signature()
works for built-in function types across Python versions.
PyCFunction closures lack the signature metadata and calling
conventions that Hypothesis requires on Python 3.14. Use inline
Python with functools.wraps instead.
The ci profile configures retries=3 and fail-fast=false, but
CI was running with the default profile which has neither.
@MatthewMckee4 MatthewMckee4 merged commit 003ed9a into main Feb 17, 2026
16 of 17 checks passed
@MatthewMckee4 MatthewMckee4 deleted the async-test-support branch February 17, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions/fixtures Related to fixtures test-running Related to running tests with karva

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fully support async

1 participant