Skip to main content

Stand-alone Assertions

Project description

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

Project details


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.14.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asserts-0.14.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file asserts-0.14.0.tar.gz.

File metadata

  • Download URL: asserts-0.14.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-87-generic

File hashes

Hashes for asserts-0.14.0.tar.gz
Algorithm Hash digest
SHA256 d267a3af64915215b70b5a306662cb2ef895ec359b39585308e91bd3134fa1ab
MD5 e50905986720b50e52404546a8d7d7c7
BLAKE2b-256 f2e731db2db2ee9c499e9cb027367a5a37631221ab316ff304f8eff3f5792c9a

See more details on using hashes here.

File details

Details for the file asserts-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: asserts-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-87-generic

File hashes

Hashes for asserts-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9cf22949bf5581b53203079eec91654e82d30ee1b9834f322b96ecf61e80878
MD5 1867c28e580db3ff10e595e44fdaa7a4
BLAKE2b-256 ba87999ca201ec238725acbf09e52c84dca8051a3c09800cea0ee35ac882be9e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page