Overview of Testfixtures capabilities
mainTestfixtures is a collection of Python helpers and mock objects designed to simplify automated testing. It provides specialized tools for several testing domains:
- Assertions & Comparisons: Deeply nested diffs for complex data (pandas, polars, numpy, pydantic) and flexible matchers like
like,sequence, andRangeComparison. - Mocking: Swapping objects, classes, or methods using
Replacer(with automatic restoration), and mocking environment variables or module globals. - Time/Date Mocking: Drop-in replacements for
datetime,date, andtimeAPIs that handle timezones and explicit time ticking. - Subprocesses & CLI: Mocking
subprocess.PopenwithMockPopenand end-to-end testing of entry-point scripts withCommand. - Output & Logging: Capturing logs (including
loguruandstructlog) viaLogCapture, and capturing stream output (likeprint) viaOutputCapture. - Filesystem: Sandboxed directory management with
TempDirectoryfor file/directory assertions and structured data serialization (JSON, YAML, TOML). - Exceptions & Warnings: Verifying that specific exceptions, assertion failures, or warnings are raised using
ShouldRaise,ShouldAssert,ShouldWarn, andShouldNotWarn. - Framework Specifics: Specialized helpers for Django models and Twisted logging.