A collection of helpers and mock objects for unit tests and doc tests.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testfixtures-12.3.0.tar.gz.
File metadata
- Download URL: testfixtures-12.3.0.tar.gz
- Upload date:
- Size: 201.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d807ceb9bdd6ea7cc0663370dd5568339056b35dc15c26effd1ae267e323acf1
|
|
| MD5 |
60ba50953b539c787c353d0e1de5c38b
|
|
| BLAKE2b-256 |
114db1c5fae372cd46b7bc1ec1dbca6efecaef8fe1e4edad203cc6e36cd5eafd
|
Provenance
The following attestation bundles were made for testfixtures-12.3.0.tar.gz:
Publisher:
release.yml on simplistix/testfixtures
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testfixtures-12.3.0.tar.gz -
Subject digest:
d807ceb9bdd6ea7cc0663370dd5568339056b35dc15c26effd1ae267e323acf1 - Sigstore transparency entry: 2120418905
- Sigstore integration time:
-
Permalink:
simplistix/testfixtures@f4ea6f22b060cebe0ae981b5c2950421d6bd9262 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/simplistix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f4ea6f22b060cebe0ae981b5c2950421d6bd9262 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file testfixtures-12.3.0-py3-none-any.whl.
File metadata
- Download URL: testfixtures-12.3.0-py3-none-any.whl
- Upload date:
- Size: 69.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da013e07f1e850b4d92ea6045c4a71f49d6ddcaab11c8b29f65ea38ff678aee8
|
|
| MD5 |
e7abbc9dd28169d1a05de7b9c2e9a949
|
|
| BLAKE2b-256 |
1c7ccf6a4bd936b0d8377992a07fe94ae9f6844e728fcfaa006b7ff9e059a038
|
Provenance
The following attestation bundles were made for testfixtures-12.3.0-py3-none-any.whl:
Publisher:
release.yml on simplistix/testfixtures
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
testfixtures-12.3.0-py3-none-any.whl -
Subject digest:
da013e07f1e850b4d92ea6045c4a71f49d6ddcaab11c8b29f65ea38ff678aee8 - Sigstore transparency entry: 2120419076
- Sigstore integration time:
-
Permalink:
simplistix/testfixtures@f4ea6f22b060cebe0ae981b5c2950421d6bd9262 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/simplistix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f4ea6f22b060cebe0ae981b5c2950421d6bd9262 -
Trigger Event:
workflow_run
-
Statement type: