pytest-dev / pytest-dev/pytest
Create a pytest plugin that is the official methodology for managing resource lifecycles
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
What's the problem this feature will solve?
Partitioned off of https://github.com/pytest-dev/pytest/issues/5243
When a fixture creates an external resource, this plugin would provide a mechanism to handle gracefully tearing down that resource when the process terminates due to a SIGTERM so that there is no resource leak bugs in a user's test suite. An official pytest subproject would save everyone from re-inventing the wheel to deal with such a common bug.
Describe the solution you'd like
A method to register a resource manager instance (perhaps using a Command design pattern) within a fixture.
A suggested solution might go like this:
There is a resource manager that is an abstraction requiring definitions by the user for how to setup and how to teardown the resource it will manage. Instances of the resource manager can be used in fixtures to easily setup, yield, and teardown resource -- and, in addition, will gracefully teardown any resources when a SIGTERM is sent to the process.
When the fixture is invoked:
- the resource manager instance is automagically registered with the SIGTERM handler
- the resource manager instance is used to setup its resource
When the fixture returns from yielding:
- the resource manager instance is used to teardown its resource
- the resource manager instance is automagically unregistered from the SIGTERM handler
When a SIGTERM is caught:
- each resource manager instance registered with the SIGTERM handler is used to teardown its resource
Race Conditions and other issues are left to the implementor.
Alternative Solutions
There are no supported alternatives. Especially none that would scale out to N resources. Nor any that would follow best practices for terminating processes gracefully.
Additional context
The following proposal is not considered suitable by pytest developers:
Contributor guide
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 reading the partitioned issue #5243, its linked comment, and the referenced termination guidance; no repository files or tests are identified here. Define the plugin's lifecycle and SIGTERM behavior, including registration, cleanup, and race conditions, then establish agreed implementation scope and acceptance criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100