A fluent DSL for python assertions.
Project description
Asserto:
Asserto is a clean, fluent and powerful assertion library for python. We recommend using pytest as a test
runner but asserto will work well with any test runner.
Asserto was developed using pytest as it's test runner and has a
pytest-assertoplugin that exposes asserto through a fixture. Asserto will work on any runner or even without one. Note: It is common practice for a test runner to apply assertion rewriting to change the behaviour of theassertkeyword under the hood.
The main features of asserto are (and will be):
- Chainable and Fluent API.
- Ability for both
HardandSoftassertions. - Rich diffs to highlight problems, reduce churn and improve effeciency and debuggability.
- Dynamic assertions; check any obj attribute or invoke any of it's function types.
- Robust set of methods out of the box for common types.
- Extensibility. Bolt on your own assetions at runtime.
- Human error detection, elaborate warnings when something is amiss.
- Much more to come.
Usage:
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asserto-0.0.4a0.tar.gz.
File metadata
- Download URL: asserto-0.0.4a0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1022-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bea1b8b840bc44e480118e3a28c9a52b465ebb06e166fc63f9567715db47477
|
|
| MD5 |
30e59a2e0c3e7cf6c67bd8dcfc105a1f
|
|
| BLAKE2b-256 |
c0527dc69d50894ebd09a050f6cdb63edfdc0ac68868980c8b8e5830d8ecdb2f
|
File details
Details for the file asserto-0.0.4a0-py3-none-any.whl.
File metadata
- Download URL: asserto-0.0.4a0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1022-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d06d27e5892ce88a8024cb6ef3442e744a2070b0c3b031e3b8a53a680364f405
|
|
| MD5 |
cfdb47c93759ffc11de8077d59c94be3
|
|
| BLAKE2b-256 |
3277f62094204ebdc7dc42be357c467aa7ce5e17cfb1bc4ffeb6b370e5805895
|