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 Distributions

asserts-0.9.1-py3.5.egg (23.5 kB view details)

Uploaded Source

asserts-0.9.1-py2.py3-none-any.whl (11.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file asserts-0.9.1-py3.5.egg.

File metadata

  • Download URL: asserts-0.9.1-py3.5.egg
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.8.1 pkginfo/1.2.1 requests/2.12.4 setuptools/33.1.1 requests-toolbelt/0.7.0 clint/0.5.1 CPython/3.5.3 Linux/4.19.0-0.bpo.1-amd64

File hashes

Hashes for asserts-0.9.1-py3.5.egg
Algorithm Hash digest
SHA256 b3c76e7c495b5362a112d504e147394e12344c4eb9563a95e8c87c4484e15b62
MD5 b0ffd7d006fc7d16166cb168944ff3b4
BLAKE2b-256 a3eb0edee421cae8e0a8e87df6d083ba3e05bf2f65336773ed520c4b93183ca7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asserts-0.9.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for asserts-0.9.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a33eed1fbddc053a929011025d6e8589c9e1ba0e13de6ae26d1f76c4f807f8d4
MD5 59f105705a52547c9c59f8c48052f35e
BLAKE2b-256 00bf6b059c76d427ee802c9372467e344245aaedfef1024333dee76c8748c486

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