Adapt to pytest-asyncio 1.0.0 with multi-scoped event loops co-existing at the same time [1st attempt]#7
Closed
Adapt to pytest-asyncio 1.0.0 with multi-scoped event loops co-existing at the same time [1st attempt]#7
Conversation
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
4 tasks
Owner
Author
|
Closing in favour of a more simple and seemingly feature-aligned (with pytest-asyncio): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Still work in progress! But generally works on a sample snippet.
TODOs:
start=…,end=…(now: assumed to be scalar).Pytest-asyncio 1.0.0 removed the
event_loopand is now based onevent_loop_policywith multi-scoped fixtures. It was deprecated since 0.23.0, but finally removed in 1.0.0.This breaks several conceptual(!) assumptions for looptime:
Looptime assumed that every test lives in its own tiny universe that starts with the big bang at time 0 by default (
looptime(start=…)mark) and does not share the event loop with other tests.Now, the event loop is shared with tests in the scope (session, module, etc). Which means, the time in every test cannot be guaranteed to start with 0.
If it is forced to 0, then the event loop's time is non-monotonic, i.e. it goes forward in a test A, then resets to 0, goes forwards again in test B, so on. This can lead to undesired effects, such as events/callbacks happening "before" they were scheduled, loop-clock-wise.
In order to resolve this problem, looptime has no choice but to introduce a few minor but breaking changes:
loop.time()is not guaranteed to start with 0 for every test. It can be any value. Still 0 for function-scoped event loops.looptime(a numeric-like fixture) must be used for assertions of the test time.The more verbose version of this explanation is in the
plugin.pydocstring — for future read.Solves #5
The sample snippet used for manual testing: