pytest-dev / pytest-dev/pytest-asyncio

Concurrent async fixture setup / teardown

Open
#118 3 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.7k
Forks
207
Avg merge
5h 35m
Merged PRs (30d)
9

Description

This is more an idea / question how hard it would be.

While pytest ensures stable fixture order, it's made with synchronous fixtures in mind.

pytest-asyncio on the other hand allows for async fixtures and typically async test cases imply async code under test which implies async dependencies which imply async fixtures.

Thus, how about running setup and teardown asynchronously too, for example:

@pytest.fixture
async def A():
    ...
    yield
    ...

@pytest.fixture
async def B(A):
    ...
    yield
    ...

@pytest.fixture
async def C(A):
    ...
    yield
    ...

@pytest.fixture
async def D(B, C):
    ...
    yield
    ...

Would run as:

  • A setup
  • asyncio.gather(B setup, C setup)
  • D setup
  • test case
  • D teardown
  • asyncio.gather(B teardown, C teardown)
  • A teardown

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the issue's async fixture dependency example and how pytest currently orders fixture setup and teardown. Determine whether concurrent setup and teardown can preserve dependency ordering and cleanup guarantees. Done means the supported behavior and scope are defined, with tests covering the proposed execution order.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.