Skip to main content

Build Status PyPI version

smart-assertions

Soft assertions for Python

Installation

    pip install smart-assertions

Usage

Assertion is performed immediately after the call soft_assert(), but the expected result is obtained only after the call verify_expectations()

Quick example:

    from  smart_assertions import soft_assert, verify_expectations

    def test_something():
        soft_assert(1 == 1)
        soft_assert(2 > 1, 'Message if test failed')
        soft_assert('one' != 'two', 'Some message')
        verify_expectations()

You can use asserts in loop:

    from  smart_assertions import soft_assert, verify_expectations

    def test_asserts_in_loop():
        for number in range(1, 10):
            soft_assert(number % 2 == 0, '{} is not a multiple of 2'.format(number))
        verify_expectations()

Also you can use it with pytest parametrized tests:

    import pytest
    from  smart_assertions import soft_assert, verify_expectations

    @pytest.mark.parametrize("number", list(range(1, 10)))
    def test_pytest_example(number):
        soft_assert(number % 2 == 0)
        verify_expectations()

Example of output:

    AssertionError: Failed conditions count: [ 4 ]

    1. Exception: Custom message if test failed
    Fail in "/Users/nromanov/Documents/smart-assertions/unittest_example.py:28" test_mixed()

    2. Exception: Lists not equals
    Fail in "/Users/nromanov/Documents/smart-assertions/unittest_example.py:30" test_mixed()

    3. Exception: Your custom message; 4 < 5!
    Fail in "/Users/nromanov/Documents/smart-assertions/unittest_example.py:32" test_mixed()

    4. Exception: one != two
    Fail in "/Users/nromanov/Documents/smart-assertions/unittest_example.py:34" test_mixed()

More examples you can find in unittest_example.py

Metadata

Release files for smart-assertions 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smart-assertions 1.0.2
File Size Uploaded Provenance
smart-assertions-1.0.2.tar.gz 2.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for smart-assertions 1.0.2
File Interpreter ABI Platform
smart_assertions-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 5.7 kB

Release files / smart-assertions-1.0.2.tar.gz

Download URL smart-assertions-1.0.2.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8806bd3c5bca825b4a62ba46a66b08eb4f2b584e128e5b37aeaa4a3eb93a8809
BLAKE2b-256 checksum
How to use checksums
1ca43dcf9b3f974c6619e808723928f415384e5d4634cfcd0fc319699e5d3810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0

Release files / smart_assertions-1.0.2-py3-none-any.whl

Download URL smart_assertions-1.0.2-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d605b55caf41acd5f255b9518c518ac0d79b92d6371baab3f58db43fd0131be3
BLAKE2b-256 checksum
How to use checksums
26054892f1eaa7bc2c5bf8003bea460a31acb7014632f84819720cd30a339ac1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.0

Security for smart-assertions 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page