-
Notifications
You must be signed in to change notification settings - Fork 137
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
Run all sync/async fixture/test code under the same contextvars.Context #618
base: master
Are you sure you want to change the base?
Conversation
Why is there a |
I wanted to write Are you opposed to including |
You can use if TYPE_CHECKING:
from typing_extensions import ParamSpec
_P = ParamSpec("_P") |
d028cca
to
d4977b0
Compare
I have added a bit of reentrancy management to the test context runner in order to support usage of Attempting to support usage of
I think that the implementation is mostly where I want it, though of course feedback and improvement suggestions are welcome. The only question for me would be to think about what to document about the new context management behavior - here are my ideas:
|
I thought about this PR even more, and two things came to mind: First, because of the way this PR modifies the way that non-async code runs, it poses a risk of new bugs (with other
Second, it came to mind that, in AnyIO 3 (because of the way that the test running task was managed), it was implicit that every |
…vars.Context-like object
…y transfers caller arguments This should remove the deprecation warning about 3-args form of .throw usage in unit tests on Python 3.12+.
…ous fixture definition
41b4cb0
to
e305e8c
Compare
@agronholm Have you had time to look at this PR and the associated comments? |
From your previous comments, I thought you had run into a dead end with this effort. The pre-commit failures need to be addressed at the minimum. |
@agronholm: I guess I must be too chatty, I was really waiting on a response from you in this PR, I really do not have any blocker (however, my other contemporaneous PR, #616, was at a dead end, so maybe I could have been clearer in communication). That is, the question that I need you to answer is the one about how to manage the risk associated to the way that this PR changes the behavior of the anyio pytest plugin:
The pre-commit failure is due to having just updated to the last version of the main branch - I will get to it once I have an answer on the above question |
I'd rather not break anyone's test suite in a minor release. Now that I know this is just pending my review, I'll take a deeper look and try to think how I want to mitigate the issue. |
I also want to say, for the record, that if you agree with integrating the principle of this PR in |
I'm currently busy on another project, but I will get to this. I need to take some time to understand it myself. It would be a good idea to write that documentation regardless (changing semantics w/o documentation updates is a no-no). |
So, here is my proposal for fixing #614
It follows the second approach outlined in #616 (comment), namely that it uses a session-scoped
contextvars.Context
object to run all fixtures and tests, whether asynchronous or synchronous.It works better than I had hoped for, and it does not even require any modification of the
TestRunner
backend implementations.I have created this PR as a draft because I suspect that reentrancy related to the usage of
getfixturevalue
does not work, but I will need to confirm it with a test case and I already have an idea to make reentrancy work (I actually had reentrancy working but I removed it because it was in the way of debugging all the ways that the tests were failing at the time)