--- id: pytest-factoryboy version: "2.8.1" license: MIT license_treatment: permissive maintenance: active --- # pytest-factoryboy — Factory Boy support for pytest. License: permissive · Maintenance: active · Downloads: 2.8M/mo ## What it is and what it does pytest-factoryboy bridges factory_boy and pytest by automatically converting factory classes into pytest fixtures. Instead of manually instantiating test objects or writing fixture boilerplate, you register a factory once and pytest injects instances directly into test functions. The package creates both model fixtures (instances) and factory fixtures (the factory itself), plus attribute fixtures that let you override individual fields via pytest parametrization. The integration handles factory_boy's advanced patterns: SubFactory relationships become fixture dependencies, related factories are injected automatically, and post-generation hooks work as fixtures. You can register the same factory multiple times with different names, specialize fixtures with keyword arguments during registration, and use LazyFixture to inject other fixtures as attribute values. This approach reduces boilerplate and makes test setup declarative and composable. Use it for: - Create reusable test fixtures for model objects without writing fixture functions. - Parametrize test object attributes via pytest.mark.parametrize without modifying factory definitions. - Build complex object graphs with SubFactory relationships that automatically resolve as fixture dependencies. - Register multiple instances of the same factory with different names for testing relationships between objects. - Override factory attributes at registration time to create specialized fixture variants for different test scenarios. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Integrates factory_boy with pytest to register factories as fixtures, enabling dependency injection and parametrization of test object creation. Yes. This is a mature, actively maintained package (first release 2015-04-09, latest 2025-07-01) with no known vulnerabilities, low install friction, and permissive MIT licensing. It solves a real pain point—combining factory_boy's declarative test data with pytest's fixture system—and is widely used (top 5000 PyPI packages). Install it if you use factory_boy and pytest together. ## Install pip install pytest-factoryboy uv add pytest-factoryboy poetry add pytest-factoryboy ## Installing pytest-factoryboy Before you install: Low friction: pure Python wheel with five runtime dependencies (factory_boy, inflection, packaging, pytest, typing_extensions), all common and stable. Active maintenance with latest release 2025-07-01 and no known vulnerabilities. License in practice: MIT license is permissive; you can use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions. Quickstart: pip install pytest-factoryboy from pytest_factoryboy import register import factory @register class AuthorFactory(factory.Factory): class Meta: model = Author name = "Charles Dickens" def test_author(author): assert author.name == "Charles Dickens" Requires Python 3.9 or later; factory_boy and pytest must be installed. Verify before relying: - Whether the package supports factory_boy's full feature set (SubFactory, RelatedFactory, post-generation) without limitations. - Performance characteristics when registering many factories or running parametrized tests at scale. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 2.8M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest factory fixtures, factory_boy pytest integration, test data factory fixtures, pytest dependency injection, factory pattern testing, pytest model fixtures, parametrized test factories, pytest-plugin, test-fixtures, factory-pattern [View on SkillFed](https://skillfed.io/packages/pytest-factoryboy) · [View on PyPI](https://pypi.org/project/pytest-factoryboy/)