polyfactory

Generate validation-passing mock data for Litestar models across Pydantic, msgspec, dataclasses, attrs, and SQLAlchemy.

13|Updated Apr 15, 2026
One-click install
npx skills add https://github.com/litestar-org/litestar-skills --skill polyfactory
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: polyfactory
Source: https://github.com/litestar-org/litestar-skills/tree/main/plugins/litestar/skills/polyfactory
Command: npx skills add https://github.com/litestar-org/litestar-skills --skill polyfactory

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill eliminates the tedious, error-prone work of manually writing test fixtures for Litestar application models, ensuring generated mock data always passes validation constraints without custom per-test setup.

Core Features & Use Cases

  • Multi-backend mock data generation: Auto-generates validation-passing instances for Pydantic, msgspec, dataclass, attrs, TypedDict, and SQLAlchemy models used in Litestar projects, respecting all model constraints and validators.
  • Native pytest integration: Registers factories as pytest fixtures with a single decorator, removing boilerplate fixture code and making factories available across test files.
  • Litestar-specific workflow guidance: Includes pre-built patterns for handler payload testing, ORM model fixture creation, SAQ task payload generation, and Channels event system tests tailored to the Litestar ecosystem.
  • Use Case: When testing a Litestar order creation endpoint that accepts a msgspec DTO, use this Skill to auto-generate valid request payloads and wire nested customer model data automatically instead of hand-coding test values.

Quick Start

Use the polyfactory skill to generate a valid mock msgspec DTO payload for your Litestar order creation endpoint test.

Frequently Asked Questions about polyfactory

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate valid mock test data for Litestar and msgspec models?

You can generate mock test data for Litestar and msgspec models using polyfactory, which auto-creates validation-passing instances that respect all model constraints, validators, and cross-model relationships without manual fixture coding.

How do I create pytest fixtures for SQLAlchemy models in a Litestar project?

Creating pytest fixtures for SQLAlchemy models in Litestar is done by registering polyfactory factories as pytest fixtures with a single decorator, making them available across all test files and removing boilerplate fixture code.

Can I auto-generate nested mock payloads for Litestar endpoint tests?

Yes, you can auto-generate nested mock payloads for Litestar endpoint tests with polyfactory, which supports cross-model relationship wiring to automatically populate nested customer or order model data for handler payload testing.

Does polyfactory support generating test data for SAQ task payloads and Channels events?

Yes, polyfactory supports generating test data for SAQ task payloads and Litestar Channels event system tests, providing pre-built patterns tailored to the Litestar ecosystem for these specific testing workflows.

What is the best way to generate deterministic test fixtures for Pydantic models?

The best way to generate deterministic test fixtures for Pydantic models is using polyfactory, which produces constraint-aware mock data that natively integrates with pytest via built-in fixture registration for consistent test results.

Why does my manually coded test data fail Litestar model validation?

Manual test data often fails Litestar model validation because it doesn't account for all constraints and validators, whereas polyfactory auto-generates validation-passing mock data that inherently respects all model requirements.