Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/srittau/python-asserts
Stand-alone Assertions for Python
https://github.com/srittau/python-asserts
assertions python python2 python3 testing unittest unittesting
Last synced: about 1 month ago
JSON representation
Stand-alone Assertions for Python
- Host: GitHub
- URL: https://github.com/srittau/python-asserts
- Owner: srittau
- License: mit
- Created: 2014-02-21T11:18:09.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2024-04-08T06:44:43.000Z (7 months ago)
- Last Synced: 2024-04-08T07:47:23.025Z (7 months ago)
- Topics: assertions, python, python2, python3, testing, unittest, unittesting
- Language: Python
- Homepage:
- Size: 262 KB
- Stars: 12
- Watchers: 6
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Asserts
[![License](https://img.shields.io/pypi/l/asserts.svg)](https://pypi.python.org/pypi/asserts/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/asserts)](https://pypi.python.org/pypi/asserts/)
[![GitHub](https://img.shields.io/github/release/srittau/python-asserts/all.svg)](https://github.com/srittau/python-asserts/releases/)
[![pypi](https://img.shields.io/pypi/v/asserts.svg)](https://pypi.python.org/pypi/asserts/)
[![GitHub Actions](https://img.shields.io/github/actions/workflow/status/srittau/python-asserts/test-and-lint.yml)](https://github.com/srittau/python-asserts/actions/workflows/test-and-lint.yml)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:
```python
>>> 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:
```python
>>> assert_equal(13, 14, msg_fmt="{got} is wrong, expected {expected}")
Traceback (most recent call last):
...
AssertionError: 14 is wrong, expected 13
```