Skip to main content

Stand-alone Assertions

Project description

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 Distribution

asserts-0.6.tar.gz (8.4 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: asserts-0.6.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for asserts-0.6.tar.gz
Algorithm Hash digest
SHA256 76f5ec062abb8cc0fd3361d328faef0fa8ccb6fe7f9fd4b1369bc71742f0ce15
MD5 c9d18a8220c6ff518437a30155107117
BLAKE2b-256 0e996646ec116630c776163dc7fd6cc7e2b89d7f1d5eec80a1b79b48cf71149e

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