Skip to content

Conversation

@nolar
Copy link
Owner

@nolar nolar commented Dec 24, 2025

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).

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.

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>

---

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).

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
@coveralls
Copy link

coveralls commented Dec 24, 2025

Pull Request Test Coverage Report for Build 20489209796

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.09%) to 63.701%

Files with Coverage Reduction New Missed Lines %
looptime/plugin.py 1 68.33%
Totals Coverage Status
Change from base Build 20388561559: -0.09%
Covered Lines: 267
Relevant Lines: 444

💛 - Coveralls

1 similar comment
@coveralls
Copy link

Pull Request Test Coverage Report for Build 20489209796

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.09%) to 63.701%

Files with Coverage Reduction New Missed Lines %
looptime/plugin.py 1 68.33%
Totals Coverage Status
Change from base Build 20388561559: -0.09%
Covered Lines: 267
Relevant Lines: 444

💛 - Coveralls

@nolar nolar merged commit 513d4fa into main Dec 24, 2025
11 checks passed
@nolar nolar deleted the drop-noise branch December 24, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants