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.12.0.tar.gz
(12.6 kB
view details)
Built Distribution
asserts-0.12.0-py3-none-any.whl
(12.4 kB
view details)
File details
Details for the file asserts-0.12.0.tar.gz
.
File metadata
- Download URL: asserts-0.12.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.9.2 Linux/5.10.0-18-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbf0143dc12132f043ac8296fce6e0a5ab72dbaa0b7369cdd33868426f2487f9 |
|
MD5 | c61fe77b2313309424f2f9f6fdd22d81 |
|
BLAKE2b-256 | 8aa7b7517b819bd2e7d1231de6b2a781c10eca96272dcb5b48a91279ce39ecd5 |
File details
Details for the file asserts-0.12.0-py3-none-any.whl
.
File metadata
- Download URL: asserts-0.12.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.2.1 CPython/3.9.2 Linux/5.10.0-18-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7009950d1baa3238862ee8410b1fd2842993982e7d8d15fc4b8e1a40f5211469 |
|
MD5 | e5dadd6d800b93effd6a9d573afe77a3 |
|
BLAKE2b-256 | 679210ab7193fee95ef3f772c49a1c96ac4a7f39cf1fd1e4d05fe2da881a4725 |