Stand-alone Assertions
Project description
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
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
asserts-0.13.0.tar.gz
(12.8 kB
view details)
Built Distribution
asserts-0.13.0-py3-none-any.whl
(12.8 kB
view details)
File details
Details for the file asserts-0.13.0.tar.gz
.
File metadata
- Download URL: asserts-0.13.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.5.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57f365b7bb4dbff640e5e4b1c1ccec6b5e6181cee9b4e42fea15428a86cc9541 |
|
MD5 | d3dd57a344d6e70650f7ee5c202a2bd3 |
|
BLAKE2b-256 | f42de56ef6aa00f5d3098b5c5b594098d390249b6c1dd15fcc1a0afbb0322efa |
File details
Details for the file asserts-0.13.0-py3-none-any.whl
.
File metadata
- Download URL: asserts-0.13.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/6.5.0-25-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b598b12fde1d2c6296cf5a14bfa2c20c42344eaa66779dca113b5960a4288612 |
|
MD5 | 544ee07647ba04849ec163c3abe278ab |
|
BLAKE2b-256 | f159d129fc21c196d3b6283c61c4968ee522f544e6d8432661665228b6725859 |