GitXplorerGitXplorer
s

python-asserts

public
14 stars
0 forks
5 issues

Commits

List of commits on branch main.
Verified
f93817f4698f22a6e233dc58b86ab2eaf1346376

Bump ruff from 0.8.6 to 0.9.1 in the dependencies group (#150)

ddependabot[bot] committed 5 days ago
Verified
0a3bff2380fd700a86b56b16354c95d7c860c44f

Bump ruff from 0.8.4 to 0.8.6 in the dependencies group (#148)

ddependabot[bot] committed 12 days ago
Verified
0762cadddffcc53bffea3c3b655f0992f9e9366e

Bump mypy from 1.14.0 to 1.14.1 in the mypy group (#149)

ddependabot[bot] committed 12 days ago
Verified
93eb095b605d1bea300cf0d548b2e6fea29eb520

Bump ruff from 0.8.3 to 0.8.4 in the dependencies group (#146)

ddependabot[bot] committed a month ago
Verified
f23f31f528d3bc2ec58dd18b2a6cee26abaaf5e5

Bump mypy from 1.13.0 to 1.14.0 in the mypy group (#147)

ddependabot[bot] committed a month ago
Verified
d002856512431da2b36ff5627b45e3d89c8f19ce

Bump ruff from 0.8.2 to 0.8.3 in the dependencies group (#145)

ddependabot[bot] committed a month 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