Drop unused code & clarify comments #19
Merged
+14
−54
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.
It was a draft for the case when the fixture's scope is stacked — in case the same-named fixture is initialised several times at different scopes (which is wrong by itself).
This approach was never implemented, but the code leftovers sneaked into the codebase: the state of fixtures was persisted, but never used.
The unused code was supposed to be used in this PR, but the future of this PR is uncertain. The code can be restored there.
Additionally, there is a bug in pytest since 2019 (6 years), which prevents using this approach: pytest-dev/pytest#5848 — the post-finalizer hook is called multiple times, depending on the number of dependencies of the fixture itself. The fixture finalizer is executed only once, as expected. Either way, this prevents proper accumulation of the stack-like structures based on the number of calls.
In practice, this led to errors like "RuntimeWarning: Fixture 'unused_tcp_port' not found in the cache of scopes" — for all the fixtures of pytest-asyncio specifically — because the stack item was added once, but then removed 2+ times from the stack.
It is easier to drop the assumption that the same-named fixture can under some circumstances be initialized twice at the same time (overlapping). This makes the post-finalizer hook unneeded entirely.
A reminder though: this does NOT help put the fixtures under any kind of automated time compaction mode: while the fixture setup can be wrapped properly (because there is a proper hook), the fixture teardown cannot (because there is no hook for the finalizer — only for the post-finalizer, which is too late).