A pytest fixture can reach a second yield after the first, which pytest rejects
What it finds
pytest runs a generator fixture up to its yield for setup and resumes it once for teardown. If the teardown reaches another yield, pytest fails the test with an error about the fixture. Branches that each yield once, or a yield followed by return, are fine and not reported.
From the rule's source, fixture_yields_twice.rs.
import pytest @pytest.fixturedef conn(flag): if flag: yield 1 else: yield 2 @pytest.fixturedef twice(): yield 1 yield 2tx0 reports: this fixture can reach a second yield @pytest.fixturedef early(flag): if flag: yield 1 return yield 2 @pytest.fixturedef single(): yield 1 cleanup() Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:fixture-yields-twice" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:fixture-yields-twice] reason="..."tx0 explain tx0/python:fixture-yields-twice shows the same in the terminal. Found a false positive? Report it.