# How to Provide Test Fixtures for Django Models in Pytest

DevFeed: [How to Provide Test Fixtures for Django Models in Pytest](<https://devfeed.tech/articles/how-to-provide-test-fixtures-for-django-models-in-pytest-33900.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-pytest-fixtures>)

Author: Haki Benita

Published: 2020-04-07T21:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [Django](<https://devfeed.tech/topics/django.md>), [Pytest](<https://devfeed.tech/topics/pytest.md>), [test](<https://devfeed.tech/topics/test.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [dependency](<https://devfeed.tech/tags/dependency.md>), [django](<https://devfeed.tech/tags/django.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [pytest](<https://devfeed.tech/tags/pytest.md>), [python](<https://devfeed.tech/tags/python.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

This tutorial explains how to maintain flexible, usable test fixtures for Django models with Pytest. It covers setting up Pytest in a Django project, creating fixtures, defining fixture dependencies, and applying a "factory as a service" pattern to simplify test data setup.

## Source excerpt

One of the most challenging aspects of writing good tests is maintaining test fixtures. Good test fixtures motivate developers to write better tests, and bad fixtures can cripple a system to a point where developers fear and avoid them all together. The article covers everything from setting up Pytest for a Django project, creating test fixtures and how to create dependency between fixtures.