Skip to main content

A fluent DSL for python assertions.

Project description

Asserto

version codecov docs

Asserto

Asserto is a clean, fluent and powerful assertion library for python. We recommend using pytest as a test runner (as asserto has been developed using it internally) however any test runner will work just fine. Using it in your framework (non-test) code is also fine as well!

The main features of asserto are (and will be):

  • Chaining and assertion fluency using a builder-esque API.
  • Hard assertions by default; but soft when used in a python context.
  • Clean, rich diffs to highlight problems and improve debuggability.
  • Dynamicism, access underlying attributes and methods on pretty much any object using attr_is(expected) syntax.
  • A robust set of APIs including all builtin types; files; regex and much, much more.
  • Extensibility; registering your own assertion functions is easy! consider sending us a patch for useful ones.
  • Automatic warnings in some cases of human error for assertions; i.e creating an instance but never checking anything.
  • Much much more.
from asserto import asserto

def test_foo() -> None:
    asserto("Hello").has_length(5).matches(r"\w{5}$").ends_with("lo").starts_with("Hel")

If you use pytest; a fixture is available for an Asserto factory function:

def test_bar(asserto) -> None:  # No imports; just use the fixture.
    asserto("Hello").has_length(5).matches(r"\w{4}$").ends_with("lo").starts_with("Hel")

If you want to check many assertions in a single test without failing until after all:

def test_baz(asserto) -> None:
    with asserto("Baz") as context:
        # asserto when used in a python context is run in 'soft' mode;
        # upon exiting the context; congregated errors are subsequently raised (if any)
        context.starts_with("B")
        context.ends_with("z")
        context.is_equal_to("Baz")
        context.is_length(2)  # Uh oh a failure!

Results in:

    def test_foo(asserto) -> None:
>       with asserto("Bar") as context:
E       AssertionError: 1 Soft Assertion Failures
E       [AssertionError("Length of: 'Bar' was not equal to: 2")]

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

asserto-0.0.3a0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asserto-0.0.3a0-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file asserto-0.0.3a0.tar.gz.

File metadata

  • Download URL: asserto-0.0.3a0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1021-azure

File hashes

Hashes for asserto-0.0.3a0.tar.gz
Algorithm Hash digest
SHA256 e6f0b46bcc2e22028c3321f68133d2bc3d97069d1bdb4b240d5473c0d50091d3
MD5 80c46d7fe8c10bb2693b726108403a56
BLAKE2b-256 16854032d6b3b3cc8f887769b2dd4c4dc576a26caa0c9823cb54ec05c15ced2b

See more details on using hashes here.

File details

Details for the file asserto-0.0.3a0-py3-none-any.whl.

File metadata

  • Download URL: asserto-0.0.3a0-py3-none-any.whl
  • Upload date:
  • Size: 11.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1021-azure

File hashes

Hashes for asserto-0.0.3a0-py3-none-any.whl
Algorithm Hash digest
SHA256 43dae16654a869feccc4c2f05f1cfb793f838b1e33541c051780f9245c7791a7
MD5 2b6bbdd46bc8308fd8891199239462a0
BLAKE2b-256 0f02b0bcb8ef71bff35a88364618da140ae74430c74058d65de172d36467d2ef

See more details on using hashes here.

Supported by

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