GitXplorerGitXplorer
s

python-asserts

public
14 stars
0 forks
5 issues

Commits

List of commits on branch main.
Verified
60e6bdf5392787b1ea655adee2ef2b9c880d5c03

Bump ruff from 0.8.1 to 0.8.2 in the dependencies group (#144)

ddependabot[bot] committed a month ago
Verified
6cc3869ee6f2736858f327e2beab7c7100f54788

Bump ruff from 0.8.0 to 0.8.1 in the dependencies group (#143)

ddependabot[bot] committed 2 months ago
Verified
23ec680fc8b4002def00ec72104aa6f7af83a772

Bump ruff from 0.7.4 to 0.8.0 in the dependencies group (#142)

ddependabot[bot] committed 2 months ago
Verified
bc0794fd915c96807d33a18e722500b41e68a53c

Bump ruff from 0.7.3 to 0.7.4 in the dependencies group (#141)

ddependabot[bot] committed 2 months ago
Verified
3e257046760d0637383b92023c95203712283d87

Bump the dependencies group with 2 updates (#140)

ddependabot[bot] committed 2 months ago
Verified
1cebe740583bdf580d73be4d4debfabd0fe80544

Bump ruff from 0.7.1 to 0.7.2 in the dependencies group (#139)

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