skillfed

testfixtures

A collection of helpers and mock objects for unit tests and doc tests.

testfixtures v12.3.0 3.4M downloads/30d#2,632 on PyPI244
Permissive license MIT Active released

What it is and what it does

Testfixtures is a mature testing utility library that bundles helpers and mock objects to simplify common testing scenarios in Python. It provides tools for asserting equality with readable diffs on nested structures, replacing objects and methods during tests, mocking datetime/time APIs, testing subprocesses and command-line scripts, capturing logs and stream output, working with temporary files and directories, and checking exceptions and warnings.

The package is designed to integrate into your test suite with minimal setup—you import the specific helpers you need and use them directly in your tests. It has no heavy dependencies beyond typing-extensions and requires Python 3.11 or later. The library covers both general testing needs and specialized scenarios like Django model comparison and Twisted logging assertions.

Use it for:

  • Assert equality on complex nested data structures with clear, readable diffs when tests fail.
  • Swap out methods or objects during a test and verify they were called correctly without manual restoration.
  • Test code that depends on the current date or time by mocking datetime and time APIs to a fixed point.
  • Capture and verify log messages from your code, including from loguru and structlog libraries.
  • Test subprocess-based code by mocking Popen without spawning real processes.
  • Verify command-line scripts work correctly end-to-end, checking output, logging, and return codes.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Testfixtures provides helpers and mock objects for writing unit and integration tests, including comparison utilities, object replacement, datetime mocking, subprocess testing, logging capture, and file/directory sandboxing.

Yes. Testfixtures is a stable, actively maintained library with no known vulnerabilities, low install friction, and permissive licensing. It solves multiple common testing problems with a cohesive API and is widely used (top 5000 PyPI packages). Install it if your test suite needs readable comparisons, object mocking, datetime control, or subprocess/logging verification.

Install

testfixtures on PyPI

pip

pip install testfixtures

uv

uv add testfixtures

poetry

poetry add testfixtures

Installing testfixtures

Before you install

Low install friction with a single lightweight runtime dependency (typing-extensions). The package is actively maintained with a recent release 37 days ago and has been in production use since 2008.

License in practice

MIT license is permissive, allowing free use, modification, and distribution in both open-source and commercial projects with minimal restrictions.

Quickstart

pip install testfixtures

from testfixtures import compare

compare(actual_value, expected_value)

Requires Python 3.11 or later.

Verify before relying

  • Whether pandas, polars, numpy, and pydantic support mentioned in the description requires those packages as optional dependencies or if they are tested only when present.
  • Whether loguru and structlog integration requires those packages as optional dependencies or if LogCapture works without them.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.11)
Install friction low — pure-Python wheel
Runtime dependencies 1 — typing-extensions
Maintenance actively maintained — 37 days since the last release
Last repo commit
First released
Downloads 3,405,022/month — #2,632 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: testfixtures-12.3.0-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3

Tags

mock objects for testingtest fixtures and helperscompare and assert equalitymock datetime and timecapture logs and outputmock subprocesstemporary test directories
mockingtest-utilitiesassertions

More Testing packages