import dataclasses import typing import pytest @dataclasses.dataclass class User: name: str create_user_type = typing.Callable[[str], User] @pytest.fixture() def create_user() -> create_user_type: def fixture(name: str) -> User: return User(name) return fixture def test_user(create_user: create_user_type): user = create_user('foo') assert isinstance(user, User) assert user.name == 'foo'