testfixtures 12.3.0


pip install testfixtures

  Latest version

Released: Jul 08, 2026


Meta
Author: Chris Withers
Requires Python: >=3.11

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Programming Language
  • Python :: 3

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.

12.3.0 Jul 08, 2026
12.2.0 Jun 20, 2026
12.1.0 Jun 15, 2026
12.0.1 Jun 11, 2026
12.0.0 May 23, 2026
11.0.0 Mar 09, 2026
10.0.0 Oct 29, 2025
9.2.0 Oct 13, 2025
9.1.0 Jul 08, 2025
9.0.1 Jul 04, 2025
9.0.0 Jul 03, 2025
8.3.0 Jun 07, 2024
8.2.0 May 01, 2024
8.1.0 Mar 01, 2024
8.0.0 Feb 16, 2024
7.2.2 Oct 20, 2023
7.2.1 Oct 20, 2023
7.2.0 Sep 15, 2023
7.1.0 Feb 08, 2023
7.0.4 Dec 05, 2022
7.0.3 Nov 03, 2022
7.0.2 Nov 01, 2022
7.0.1 Nov 01, 2022
7.0.0 Jul 06, 2022
6.18.5 Mar 01, 2022
6.18.4 Feb 25, 2022
6.18.3 Sep 29, 2021
6.18.2 Sep 21, 2021
6.18.1 Aug 20, 2021
6.18.0 Jul 15, 2021
6.17.1 Jan 14, 2021
6.17.0 Dec 16, 2020
6.16.0 Dec 09, 2020
6.15.0 Oct 09, 2020
6.14.2 Sep 04, 2020
6.14.1 Apr 20, 2020
6.14.0 Feb 24, 2020
6.13.1 Feb 20, 2020
6.13.0 Feb 18, 2020
6.12.1 Feb 16, 2020
6.12.0 Feb 06, 2020
6.11.0 Jan 29, 2020
6.10.3 Nov 22, 2019
6.10.2 Nov 16, 2019
6.10.1 Nov 01, 2019
6.10.0 Jun 19, 2019
6.9.0 Jun 10, 2019
6.8.2 May 04, 2019
6.8.1 May 02, 2019
6.8.0 May 02, 2019
6.7.1 Apr 29, 2019
6.7.0 Apr 11, 2019
6.6.2 Mar 22, 2019
6.6.1 Mar 13, 2019
6.6.0 Feb 22, 2019
6.5.2 Feb 18, 2019
6.5.1 Feb 18, 2019
6.5.0 Jan 28, 2019
6.4.3 Jan 10, 2019
6.4.2 Jan 09, 2019
6.4.1 Dec 24, 2018
6.4.0 Dec 19, 2018
6.3.0 Sep 04, 2018
6.2.0 Jun 14, 2018
6.1.0 Jun 06, 2018
6.0.2 May 02, 2018
6.0.1 Apr 17, 2018
6.0.0 Mar 27, 2018
5.4.0 Jan 25, 2018
5.3.1 Nov 21, 2017
5.3.0 Oct 28, 2017
5.2.0 Sep 03, 2017
5.1.1 Jun 08, 2017
5.1.0 Jun 08, 2017
5.0.0 Jun 05, 2017
4.14.3 May 15, 2017
4.14.2 May 15, 2017
4.14.1 May 15, 2017
4.14.0 May 15, 2017
4.13.5 Mar 01, 2017
4.13.4 Feb 06, 2017
4.13.3 Dec 13, 2016
4.13.1 Nov 02, 2016
4.13.0 Nov 02, 2016
4.12.0 Oct 18, 2016
4.11.0 Oct 12, 2016
4.10.1 Sep 05, 2016
4.10.0 May 17, 2016
4.9.1 Feb 23, 2016
4.9.0 Feb 18, 2016
4.8.0 Feb 02, 2016
4.7.0 Dec 10, 2015
4.6.0 Dec 03, 2015
4.5.1 Nov 23, 2015
4.5.0 Nov 13, 2015
4.4.0 Nov 02, 2015
4.3.3 Sep 15, 2015
4.3.2 Sep 15, 2015
4.3.0 Sep 15, 2015
4.2.0 Aug 11, 2015
4.1.2 Jan 30, 2015
4.1.1 Oct 30, 2014
4.1.0 Oct 14, 2014
4.0.2 Sep 10, 2014
4.0.1 Aug 04, 2014
4.0.0 Jul 22, 2014
3.0.2 Apr 07, 2014
3.0.1 Jun 10, 2013
3.0.0 Mar 05, 2013
2.3.5 Aug 13, 2012
2.3.4 Jan 31, 2012
2.3.3 Dec 12, 2011
2.3.2 Nov 10, 2011
2.3.1 Nov 08, 2011
2.3.0 Oct 11, 2011
2.2.0 Oct 04, 2011
2.1.0 Sep 29, 2011
2.0.1 Sep 23, 2011
2.0.0 Sep 23, 2011
1.12.0 Aug 16, 2011
1.11.3 Aug 03, 2011
1.11.2 Jul 28, 2011
1.11.1 Jul 28, 2011
1.11.0 Jul 27, 2011
1.10.0 Jul 19, 2011
1.9.2 Apr 20, 2011
1.9.1 Mar 11, 2011
1.9.0 Feb 11, 2011
1.8.0 Jan 14, 2011
1.8.0.dev0 Sep 07, 2010
1.7.0 Jan 21, 2010
1.6.3 Jan 20, 2010
1.6.2 Sep 23, 2009
1.6.1 Sep 07, 2009
1.6.0 May 10, 2009
1.5.4 Feb 11, 2009
1.5.3 Dec 17, 2008
1.5.2 Dec 14, 2008
1.5.1 Dec 12, 2008
1.5.0 Dec 12, 2008
1.4.0 Dec 12, 2008
1.3.1 Dec 10, 2008
1.3.0 Dec 09, 2008
1.2.0 Dec 03, 2008
1.1.0 Dec 03, 2008
1.0.0 Nov 26, 2008
1.8.0dev-r4464

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
typing-extensions (>=4.12)