-
-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers
Description
Summary
The usages in https://polyfactory.litestar.dev/latest/usage/fixtures.html suggests the fixture returns an instance of the factory class, but instead it returns the class itself. This can be shown using the example in the guide and printing the types
from dataclasses import dataclass
from datetime import date, datetime
from typing import List, Optional, Union
from uuid import UUID
from polyfactory.factories import DataclassFactory
from polyfactory.pytest_plugin import register_fixture
@dataclass
class Person:
id: UUID
name: str
hobbies: Optional[List[str]]
nicks: List[str]
age: Union[float, int]
birthday: Union[datetime, date]
@register_fixture(name="aliased_person_factory")
class PersonFactory(DataclassFactory[Person]): ...
def test_person_factory(person_factory: PersonFactory) -> None:
print(type(person_factory)) # <class 'abc.ABCMeta'>
print(type(person_factory())) # <class 'poly.PersonFactory'>
person_instance = person_factory.build()
assert isinstance(person_instance, Person)It can also be shown in FactoryFixture.__call__:
polyfactory/polyfactory/pytest_plugin.py
Lines 79 to 86 in 7d67749
| def _factory_fixture() -> type[T]: | |
| """The wrapped factory""" | |
| return cast("Type[T]", factory) | |
| caller_globals = inspect.stack()[depth][0].f_globals | |
| caller_globals[fixture_name] = fixture_register(_factory_fixture) | |
| return factory # type: ignore[return-value] |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers