Python Asserts
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
Release files for asserts 0.14.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| asserts-0.14.0.tar.gz | 12.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asserts-0.14.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.2 kB
Release files / asserts-0.14.0.tar.gz
| Download URL | asserts-0.14.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d267a3af64915215b70b5a306662cb2ef895ec359b39585308e91bd3134fa1ab
|
|
BLAKE2b-256 checksum How to use checksums |
f2e731db2db2ee9c499e9cb027367a5a37631221ab316ff304f8eff3f5792c9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-87-generic
|
Release files / asserts-0.14.0-py3-none-any.whl
| Download URL | asserts-0.14.0-py3-none-any.whl |
|---|---|
| Size | 13.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c9cf22949bf5581b53203079eec91654e82d30ee1b9834f322b96ecf61e80878
|
|
BLAKE2b-256 checksum How to use checksums |
ba87999ca201ec238725acbf09e52c84dca8051a3c09800cea0ee35ac882be9e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-87-generic
|