skillfed

fixtures

Fixtures, reusable state for writing clean tests and more.

fixtures v4.3.2 737.0K downloads/30d#5,190 on PyPI35
Permissive license Apache-2.0 or BSD Active released

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 fixtures

uv

uv add fixtures

poetry

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 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

Development Status :: 6 - MatureIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Quality AssuranceTopic :: Software Development :: TestingTyping :: Typed

Tags

test fixtures with cleanupreusable test state managementunittest fixture frameworktest setup and teardowncomposable test helpersfixture-based testingtest resource lifecycle
testing-frameworktest-fixturesunittest-utilities

More Testing packages