Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

soft-assert

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soft-assert

Soft assertions for Python/Pytest

  • 1.0.5
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc