Soft assertions for Python/Pytest
Project description
soft-asserts
Soft assertions for Python/Pytest
Installation
pip install soft-assert
Usage
Assertion is performed immediately after the call check()
,
but the expected result is obtained only after exit the context manager verify()
Quick example:
from soft_assert import check, verify
def test_something():
with verify():
check(1 == 1)
check(2 > 1, 'Message if test failed')
check('one' != 'two', 'Some message')
You can use asserts in loop:
from soft_assert import check, verify
def test_asserts_in_loop():
with verify():
for number in range(1, 10):
check(number % 2 == 0, '{number} is not a multiple of 2')
Also you can use it with pytest parametrized tests:
import pytest
from soft_assert import check, verify
@pytest.mark.parametrize('number', list(range(1, 10)))
def test_pytest_example(number):
with verify():
check(number % 2 == 0)
Example of output:
AssertionError: Failed conditions count: [ 4 ]
1. Failure: Custom message if test failed
2. Failure: Lists not equals
3. Failure: Your custom message; 4 < 5!
4. Failure: one != two
More examples you can find in test_example.py
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
soft-assert-1.0.2.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for soft_assert-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19d9cccf14c073b76a451fcc1164abfed7127ec2a5fedb13d83e2712c10b6da5 |
|
MD5 | 4edd6d7031687fabf1a46a91855b7cf7 |
|
BLAKE2b-256 | 72e1bd35bf53fad5a7e6349875fc832bc91c067166f9951eb8b8ecc7f601485c |