Skip to main content

Stand-alone Assertions

Project description

https://img.shields.io/github/release/srittau/python-asserts/all.svg https://travis-ci.org/srittau/python-asserts.svg?branch=master

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

asserts-0.7.3-py2.py3-none-any.whl (9.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file asserts-0.7.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for asserts-0.7.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 121bdb12e3f4dafde10918d47507565dd8bb72fa1ee709e4f32878f496e60865
MD5 702b861ad24f98b10f463a838055a428
BLAKE2b-256 ad312e4c3879448d0dab9b92451b846f23b9e34ca4f2be98df46c27fb6ad0669

See more details on using hashes here.

Supported by

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