fixtures
Fixtures, reusable state for writing clean tests and more.
What it is and what it does
Fixtures is a testing library that defines a contract for reusable state and support logic in unit tests. Rather than accumulating helper methods on test classes (which scales poorly and pollutes class hierarchies), fixtures lets you write standalone, composable objects that manage their own setup and cleanup. Each fixture subclasses the base Fixture class, defines _setUp to initialize state, and schedules cleanups via addCleanup; when cleanUp is called, all scheduled cleanups run in reverse order.
The library includes glue code for unittest integration via TestWithFixtures, which provides a useFixture method that automatically calls setUp, schedules cleanup, and returns the fixture. Fixtures can be composed using useFixture within other fixtures, adapted from functions via FunctionFixture, or combined with CompoundFixture. The package supports context managers and exposes diagnostic details via the testtools content API. It has no runtime dependencies and works with Python 3.10 and later.
Use it for:
- Write reusable test fixtures that manage temporary resources (files, databases, servers) without polluting test class hierarchies.
- Compose complex test state from multiple simpler fixtures using useFixture, keeping each fixture focused and independently testable.
- Adapt existing setup/teardown functions or object methods into the Fixture contract using FunctionFixture or MethodFixture.
- Ensure deterministic cleanup of test resources even when multiple cleanups fail, via the MultipleExceptions wrapper.
- Share expensive fixtures across test cases using reset() to efficiently reinitialize state without full teardown and setup.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a reusable fixture contract for unit testing that manages setup, cleanup, and state composition without requiring test class hierarchies.
Yes. Fixtures is a mature, actively maintained library with zero security issues, low install friction, and permissive dual licensing. It solves a real problem in test organization—avoiding helper method sprawl on test classes—and integrates cleanly with unittest. Install it if you write unit tests and want cleaner, more reusable test state management.
Install
fixtures on PyPI
pip
pip install fixturesuv
uv add fixturespoetry
poetry add fixturesInstalling fixtures
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a recent release and ongoing commits. Supports Python 3.10 through 3.14 and PyPy.
License in practice
Dual-licensed under Apache-2.0 or BSD (permissive). You may choose either license when using or redistributing.
Quickstart
import fixtures
import unittest
class MyFixture(fixtures.Fixture):
def _setUp(self):
self.value = 42
self.addCleanup(delattr, self, 'value')
class MyTest(unittest.TestCase, fixtures.TestWithFixtures):
def test_example(self):
fixture = self.useFixture(MyFixture())
self.assertEqual(42, fixture.value)
Verify before relying
- Whether the optional testtools dependency is required for production use or only for advanced diagnostic features
Package facts
| License | Apache-2.0 or BSD (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 142 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 737,050/month — #5,190 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: fixtures-4.3.2-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
django-fixture-magicProvides Django management commands to dump…
permissive · top 15,000 on PyPI
pytest-deadfixturesA pytest plugin that identifies unused and…
permissive · top 5,000 on PyPI
testresourcestestresources extends unittest to manage…
permissive · top 15,000 on PyPI
pytest-unused-fixturesA pytest plugin that identifies and reports…
permissive · top 15,000 on PyPI
pytest-lazy-fixturesAllows you to reference pytest fixtures…
permissive · top 5,000 on PyPI
pytest-postgresqlA pytest plugin that provides fixtures to…
copyleft · top 5,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI
oslotestoslotest provides a testing framework with…
permissive · top 15,000 on PyPI
pytest-mock-resourcesProvides pytest fixtures that spin up real…
permissive · top 15,000 on PyPI
nutterNutter is a testing framework for Databricks…
permissive · top 15,000 on PyPI