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.2a0.tar.gz (9.2 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.2a0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asserto-0.0.2a0.tar.gz
  • Upload date:
  • Size: 9.2 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.2a0.tar.gz
Algorithm Hash digest
SHA256 1c636dea0c096ba6707f1b62eee66a235f8d14bf58f1f7e9b22da50bf0388f32
MD5 e62025a43c6973f131be10e28ae31e31
BLAKE2b-256 31ec532e15bb68024291309e6498f0716781bba5593c43dfc95154b8a3888d50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asserto-0.0.2a0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 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.2a0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa6a4d9d263e016ed7f2862b2247388463cb594558e276abc4d4bc0eeab8664c
MD5 c34677fa29ac3729bf76bcc1ea188997
BLAKE2b-256 50787b9bc2f9602910cbe968fbc8d8a5c37dfa8f8bafebc84b9286488fd62794

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