-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Make it clear in the documentation that fixtures are not suitable for managing resource lifecycles #9141
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
Comments
Hi @gsmethells, Not sure I agree, "not suitable for managing resource lifecycles" is a bit strong worded. For example even if we handled I'm OK with adding a note that |
That is the essence of the necessary change to the documentation. Users should have fair warning that fixtures cannot handle:
However:
Therefore, I believe it is a fair assessment, given both those facts, that "fixtures are not fit for the purpose of resource lifecycle management." Users are deserving of a warning of this subtle issue that they are likely to run into eventually.
|
@gsmethells I recommend you take a step back and consider how you're communicating -- we understand you're passionate about this issue but you don't need to use inflammatory language to get your point across. please be nice -- there are humans on the other side of the cable as is standard in python, SIGINT is handled (via raising |
@asottile understood |
I seek to help other users than myself. I believe the best place for it, in this case, is in the documentation given the stances I learned by spending my time on these threads. The suggested solution would need further refinement to suss out issues for more complicated test suite codebases. It doesn't work for us. That can be figured out in #9142 at some point. Until then, I hope you will agree that the current documentation is not definitive concerning where the responsibility of resource lifecycle management rests and how best to go about it. I lay it out as I do in a proof format more for the formality of my thoughts than any intention to be unkind and I am sorry if it was taken otherwise. If it is any consolation, I spent a good part of my waking hours being useful regarding the Sept 30th Let's Encrypt's snafu for hundreds of clinics in every state of the U.S. (some of the largest in the country) and I'm pretty spent, but that's no excuse. |
I agree, how about something like:
My intent here is explicitly warn about the signals not handled by pytest, and provide an alternative when handling those signals is important. |
@asottile out of curiosity, what drawbacks you see in making pytest handle (I'm wondering about concrete points, not necessarily about the definition/terminology of "resource manager" vs "test runner") |
signal handlers are global and if pytest starts adding them that will interfere with execution of current code in a surprising way (I know specifically of at least one private project that breaks due to testing signal handlers directly) |
Ahh makes sense, thanks! |
@nicoddemus I'm good with the above blurb. Thanks for taking the time to write it up. |
@asottile thanks for taking the time to explain why signal handlers do not belong in pytest core. |
PR open: #9150 |
Uh oh!
There was an error while loading. Please reload this page.
What's the problem this feature will solve?
Partitioned off of #5243
Proposal: Make it clear in the pytest documentation that users are responsible for resource lifecycle management.
Currently, there are misleading examples such as:
that suggest otherwise. The above fixture from the documentation is highly suggestive that pytest believes fixtures are appropriate to use for resource management; however, pytest is only a test runner and not a resource manager according to @asottile
Describe the solution you'd like
A documentation change that makes it clear that pytest fixtures are not fit for the purpose of handling resource lifecycles in all cases (user beware). There are likely other places in the documentation that require review concerning this point.
Also, it would be useful to all users to document common ways a user can handle resource lifecycles, especially for external resources that could be leaked, that are known to work smoothly with pytest's framework.
Alternative Solutions
None
Additional context
Identified during discussions in:
The text was updated successfully, but these errors were encountered: