--- id: fixtures version: "4.3.2" license: Apache-2.0 or BSD license_treatment: permissive maintenance: active --- # fixtures — Fixtures, reusable state for writing clean tests and more. License: permissive · Maintenance: active · Downloads: 737.0K/mo ## 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 above — 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 pip install fixtures uv add fixtures poetry add fixtures ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 737.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags test fixtures with cleanup, reusable test state management, unittest fixture framework, test setup and teardown, composable test helpers, fixture-based testing, test resource lifecycle, testing-framework, test-fixtures, unittest-utilities [View on SkillFed](https://skillfed.io/packages/fixtures) · [View on PyPI](https://pypi.org/project/fixtures/)