pytest-dev / pytest-dev/pytest-xdist
Allow fixtures to execute only once in the test run (not for each worker)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.9k
- Forks
- 287
- Avg merge
- 9h 30m
- Merged PRs (30d)
- 2
Description
Use case
There is a resource that can be used in many testcases in parallel. The idea is to create a fixture that will acquire this resource before all the test cases and release it after all the test cases. In between all the test cases can use this resource, even if they run in parallel.
Alternatives
- Using locks - Complicated and adds overhead to the tests
- Checking in a fixture if the code runs on the worker thread - I found two problems with this approach. The first one is that method needs to check something very "magic"-like that can maybe change, like the "master" worker_id. The second one is that it can lead to races.
Suggested solution
Mark a fixture as "run only once"
Thank you in advance :)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how pytest-xdist creates workers and executes fixtures, then inspect the fixture lifecycle and worker communication paths. Define how a fixture marked to run once would be acquired and released across the full test run, including parallel workers, and identify tests needed to verify both single execution and resource cleanup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- distributed-systems, testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100