Skip to content

How to type yield fixtures #7809

Answered by bluetech
OlgaPaw asked this question in General
Sep 28, 2020 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Iterator[str] is actually not strong enough; the correct incantation is

from typing import Generator

@pytest.fixture()
def foo() -> Generator[str, None, None]:
    yield "foo"

I'm hoping one day generics could have defaults, in which case the type would be just Generator[str], but for now the full thing is needed.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@graingert
Comment options

Answer selected by bluetech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants