Skip to main content

Testfixtures

Docs PyPI Git

Testfixtures is a collection of helpers and mock objects that are useful when writing automated tests in Python.

The areas of testing this package can help with are listed below:

Comparing, asserting equality and explaining differences

The compare function gives readable feedback when results aren’t as expected, with clear diffs for deeply nested data structures and for objects that don’t normally support comparison. This includes first-class support for pandas and polars dataframes, numpy arrays and pydantic models. Flexible placeholder objects and matchers such as like, sequence, generator, Comparison, RoundComparison, RangeComparison, TextComparison and SequenceComparison let you assert that only part of a value matters, that a number is within a range or rounded to a precision, or that a string matches a pattern.

Mocking out objects and methods

Replacer makes it easy to swap out objects, classes or individual methods for the duration of a test, restoring the originals automatically when it ends. You point them at the thing being replaced directly rather than at a dotted string, so your type checker verifies the target and the replacement survives refactoring. replace_on_class, replace_in_module and replace_in_environ cover common cases such as methods, module globals and environment variables.

Mocking dates and times

mock_datetime, mock_date and mock_time are drop-in replacements for the datetime and time APIs, for testing code that depends on the current date or time. They cover the thorny issues of timezones, non-uniform sequences of mock time increments, explicit ticking and freezing a point in time so you don’t have to invent them from scratch.

Testing subprocesses

MockPopen lets you test code that uses subprocess.Popen without running real processes.

Testing command-line scripts

Command drives entry-point scripts end to end and checks their output, logging, mock calls and return code.

Testing logging

LogCapture captures log messages so you can check what was logged is what you expected, including from the loguru and structlog libraries.

Testing stream output

OutputCapture captures stream output, such as that from print calls or even writes made directly to file descriptors, and makes it easy to assert about.

Testing with files and directories

TempDirectory gives you a sandboxed directory to work in. It makes it easy to read and write files, serialise and deserialise structured data in formats such as JSON, YAML and TOML, create directory trees, and assert on the contents of both individual files and whole directories.

Testing exceptions and warnings

ShouldRaise, ShouldAssert, ShouldWarn and ShouldNotWarn check that a particular exception is raised, that an assertion fails with a particular message, or that a warning is issued, down to the parameters involved.

Testing when using Django

Helpers for comparing instances of Django models.

Testing when using Twisted

Helpers for making assertions about logging when using Twisted.

Metadata

Release files for testfixtures 12.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for testfixtures 12.5.0
File Size Uploaded Provenance Actions
testfixtures-12.5.0.tar.gz 208.6 kB With provenance Details for testfixtures-12.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for testfixtures 12.5.0
File Interpreter ABI Platform Actions
testfixtures-12.5.0-py3-none-any.whl Python 3 none any Details for testfixtures-12.5.0-py3-none-any.whl

Total release size: 279.8 kB

Release files / testfixtures-12.5.0.tar.gz

Download URL testfixtures-12.5.0.tar.gz
Size 208.6 kB
Tags Source
SHA-256 checksum
How to use checksums
021b3caf2b5c805edf361c7b25752f1221ac4273c8970aff6e379f8971029fe1
BLAKE2b-256 checksum
How to use checksums
d258af086aaa91a74a79005b01f4f5edeff158f5a1211cd21de5dd4b13d12401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / testfixtures-12.5.0-py3-none-any.whl

Download URL testfixtures-12.5.0-py3-none-any.whl
Size 71.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76a4f6f7bf6f3cc31d75a0a217ded4d38ceedbf30ada9302af8f647435a6cc83
BLAKE2b-256 checksum
How to use checksums
6aa20c30419fc19e2acd48dced0424c54429dc2a9ed5baf14957a56a64107417
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for testfixtures 12.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for testfixtures-12.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

12.5.0 This release

2 release files Full provenance

3.1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page