--- id: testfixtures version: "12.3.0" license: MIT license_treatment: permissive maintenance: active --- # testfixtures — A collection of helpers and mock objects for unit tests and doc tests. License: permissive · Maintenance: active · Downloads: 3.4M/mo ## 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 above — 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 pip install testfixtures uv add testfixtures 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_current - Install friction: low - Maintenance: active - Downloads: 3.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags mock objects for testing, test fixtures and helpers, compare and assert equality, mock datetime and time, capture logs and output, mock subprocess, temporary test directories, mocking, test-utilities, assertions [View on SkillFed](https://skillfed.io/packages/testfixtures) · [View on PyPI](https://pypi.org/project/testfixtures/)