Stand-alone Assertions
Project description
Stand-alone Assertions for Python
This package provides a few advantages over the assertions provided by unittest.TestCase:
Can be used stand-alone, for example:
In test cases, not derived from TestCase.
In fake and mock classes.
In implementations as rich alternative to the assert statement.
PEP 8 compliance.
Custom stand-alone assertions can be written easily.
Arguably a better separation of concerns, since TestCase is responsible for test running only, if assertion functions are used exclusively.
There are a few regressions compared to assertions from TestCase:
The default assertion class (AssertionError) can not be overwritten. This is rarely a problem in practice.
asserts does not support the addTypeEqualityFunc() functionality.
Usage:
>>> from asserts import assert_true, assert_equal, assert_raises >>> my_var = 13 >>> assert_equal(13, my_var) >>> assert_true(True, msg="custom failure message") >>> with assert_raises(KeyError): ... raise KeyError()
Failure messages can be customized:
>>> assert_equal(13, 14, msg_fmt="{got} is wrong, expected {expected}") Traceback (most recent call last): ... AssertionError: 14 is wrong, expected 13
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 Distributions
Built Distribution
File details
Details for the file asserts-0.8.1-py2.py3-none-any.whl
.
File metadata
- Download URL: asserts-0.8.1-py2.py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78c8db4c8592999953da7c25d4d9a5394546f3d3313ecb98979f344529c45096 |
|
MD5 | ded6f5aca5e4a187fc4d7dd44afda9bf |
|
BLAKE2b-256 | 6c9df4b72035926ed00ccc3d92909ced7803e8b7f8ee605c176a6412b64785aa |