Faker comes with a built-in pytest fixture. For both efficiency sake and control over the faker instance customization (e.g. custom faker providers, locales and randomness) it would be nice if there were a way to use that shared instance.
The approach I'm imagining is either as an extra option to pytest_plugin.registry_factory(... use_fake_fixture=True)
or as a completely separate pytest plugin method.
In that case, when the Factory class doesn't define its own __faker__
instance, the pytest faker
fixture would be used.
e.g.
@pytest.fixture(scope="session", autouse=True)
def faker_seed() -> int:
return 42
@pytest.fixture(scope="session", autouse=True)
def faker_session_locale():
return ['en_US']
@pytest.fixture(autouse=True)
def customize_faker(faker: Faker):
faker.add_provider(MyCustomProvider)
class MyPersonFactory(ModelFactory[Person]):
__model__ = Person
register_fixture(PersonFactory, use_faker_fixture=True)
No response
__faker__ = Faker()
instance to a sentinel value to avoid creating extra Faker
instances.Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too