Repository navigation
Conversation
phalberg
commented
Oct 4, 2026
|
|
||
|
|
||
| @pytest.fixture | ||
| def sample_fixture_yield() -> Generator[int, None, None]: |
Author
There was a problem hiding this comment.
I could also include an example of iterator for this too? If this is not already clear from this perhaps... or at least just mention it maybe
phalberg
force-pushed
the
docs/typing-yield-fixtures
branch
from
October 11, 2026 12:16
0e4e81d to
b2fabbc
Compare
This branch has not been deployed
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.
Description
While working with adding types to a codebase of mine and using mypy it was not so trivial (for me at least) that fixtures that are of Generator types, are not to be type annotated like Generators but rather their return types when used in other fixtures. Based on: https://docs.pytest.org/en/stable/how-to/fixtures.html#teardown-cleanup-aka-fixture-finalization, it became more obvious why this is the case, but it was not so easy to find this documentation, and I feel that the typing docs can also have a note for it.
Changes
Added a typing section about usage of yield based fixtures for other fixtures.
Relevant issue
No relevant issue, as I see this as small docs "enhancement".