Skip to main content

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

Release files for asserts 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asserts 0.14.0
File Size Uploaded
asserts-0.14.0.tar.gz 12.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asserts 0.14.0
File Interpreter ABI Platform
asserts-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.2 kB

Release files / asserts-0.14.0.tar.gz

Download URL asserts-0.14.0.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d267a3af64915215b70b5a306662cb2ef895ec359b39585308e91bd3134fa1ab
BLAKE2b-256 checksum
How to use checksums
f2e731db2db2ee9c499e9cb027367a5a37631221ab316ff304f8eff3f5792c9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-87-generic

Release files / asserts-0.14.0-py3-none-any.whl

Download URL asserts-0.14.0-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9cf22949bf5581b53203079eec91654e82d30ee1b9834f322b96ecf61e80878
BLAKE2b-256 checksum
How to use checksums
ba87999ca201ec238725acbf09e52c84dca8051a3c09800cea0ee35ac882be9e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.12.3 Linux/6.8.0-87-generic

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.1

2 release files

0.9.0

1 release file

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6

1 release file

0.5.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page