Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Soft assertions for Python
pip install smart-assertions
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
FAQs
Soft assertions for Python
We found that smart-assertions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.