Skip to main content

Stand-alone Assertions

Project description

https://img.shields.io/pypi/l/asserts.svg https://img.shields.io/github/release/srittau/python-asserts/all.svg https://img.shields.io/pypi/v/asserts.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()

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 Distributions

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

Built Distribution

asserts-0.10.0-py2.py3-none-any.whl (12.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: asserts-0.10.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for asserts-0.10.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d42de39290badeb1816f09bec2996912718e9b3a379a3415e6731bb0d2b271b2
MD5 b3a804d83e333d7e2e6f98df7d58064b
BLAKE2b-256 e207cbb15d287cd9424b55da504124aea3cf59fec6de870dad1f75b7c0f717aa

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