Skip to main content

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

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.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

soft_assert-1.0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file soft-assert-1.0.1.tar.gz.

File metadata

  • Download URL: soft-assert-1.0.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for soft-assert-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6de10d2271d01d9e937be840b15b08c660dde0344156f3947d7488d170b55ef8
MD5 83ae8789c3b94b3f20544cf83a19856a
BLAKE2b-256 1403045639e96fbbca4cfb0e6ad42e29b2790fcef872db1fd2b86ab4bb867937

See more details on using hashes here.

File details

Details for the file soft_assert-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: soft_assert-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for soft_assert-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea47b594be4b0f1acf93985c9ab915c74948da064e23ee56916408550024288
MD5 2da33b0843765c378d72e0a7dd20cce5
BLAKE2b-256 6b87d6e591a62bf55b81dc2129be35f875da392d58a8c7c4818720cabeb812c0

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 Sentry Error logging StatusPage Status page