GitXplorerGitXplorer
s

python-asserts

public
14 stars
0 forks
5 issues

Commits

List of commits on branch main.
Verified
8939c52a1d6e0faf8c77ea37e6dc29ed515a2b7d

Bump ruff from 0.7.0 to 0.7.1 in the dependencies group (#137)

ddependabot[bot] committed 3 months ago
Verified
0104bc8a4d5a8b670c39a4bfe70716e6984b1051

Bump mypy from 1.12.1 to 1.13.0 in the mypy group (#138)

ddependabot[bot] committed 3 months ago
Verified
577b5b66ca449f21d4f0ce0d9485a19a317f79c4

Bump ruff from 0.6.9 to 0.7.0 in the dependencies group (#135)

ddependabot[bot] committed 3 months ago
Verified
5db2c8b67504d7400f374e2394559ba84201cb6a

Bump mypy from 1.11.2 to 1.12.1 in the mypy group (#136)

ddependabot[bot] committed 3 months ago
Verified
4ebcd4830ca0416e8af6c0f211174431c0c86b6f

Bump ruff from 0.6.8 to 0.6.9 in the dependencies group (#134)

ddependabot[bot] committed 3 months ago
Verified
aef1e68d4ab6a7f7565811439e6122d7610d5d06

Bump the dependencies group with 2 updates (#133)

ddependabot[bot] committed 4 months ago

README

The README file for this repository.

Python Asserts

License PyPI - Python Version GitHub pypi GitHub Actions

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