Delayed/soft assertions for python
Project description
Python-Delayed-Assert
Delayed aka. Soft asserts for python
Few features:
- No Dependenices on any other framework/library.
- Should work with any testing framework.
- Can be use as decorator or context manager.
Installation
Install via pip
pip install delayed-assert
Install from master
pip install git+https://github.com/pr4bh4sh/delayed-assert
Uses
See example_unittest.py
for usage.
Using assertion library with lambda
Pass the assertion call as
expect(lambda: self.assertListEqual([4,5,6,2,5],[7,8]))
While I've tested only with unittest asserttion,It should be able to use any assertion library.
Keep in mind that, Python does not support statement inside lambda, so
expect(lambda: assert 1 == 1)
won't work as it is not a valid lambda expression in python
Current possible uses
def testSomething(self):
delayed_assert.expect(1 == 1) # will succeed
delayed_assert.expect(1 == 2) # will fail but won't stop execution
delayed_assert.expect(3 == 2, "Value don't match") # will fail but won't stop execution
delayed_assert.expect(3 == 3) # will succeed
# will stop execution and show the stack trace of 2nd assertion
delayed_assert.assert_expectations()
def testLambdas(self):
expect(lambda: self.assertEqual(3,4)) # will fail but won't stop execution
expect(lambda: self.assertListEqual([4,5,6,2,5],[7,8])) # will fail but won't stop execution
assert_expectations()
@delayed_assert.assert_all()
def testDecorator(self):
expect('five' == 'Six', 'String do not match')
expect([5,2] == [3,4], 'List item do not match')
expect([3,4] == [3,4], 'This message wont be printed')
# No need to call delayed_assert.assert_expectations() when decorator is used
def testContextManeger(self):
with delayed_assert.assert_all():
expect('four' == 'Six', 'String do not match')
expect([5,2] == [3,4], 'List item do not match')
expect([3,4] == [3,4], 'This message wont be printed')
# No need to call delayed_assert.assert_expectations() when using context maneger is used
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
delayed_assert-0.3.6.tar.gz
(4.3 kB
view details)
Built Distribution
File details
Details for the file delayed_assert-0.3.6.tar.gz
.
File metadata
- Download URL: delayed_assert-0.3.6.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e1c65afae4bae9c57b91c76e38287562924c9964a58c309249790c725c46239 |
|
MD5 | 01d785543256bb7e9b01594047eb9da3 |
|
BLAKE2b-256 | 1bd770b520f924b5fea6f27343044bb607afd1473af7157199ef0d23d313eb33 |
File details
Details for the file delayed_assert-0.3.6-py3-none-any.whl
.
File metadata
- Download URL: delayed_assert-0.3.6-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9987466c4d05c94af21151f27e58a8c13beba176e5f358d16c21b6abd3e6268b |
|
MD5 | fdb39a6b3430c5201350fd13888a5ebb |
|
BLAKE2b-256 | e705a5b5abc2a9479a91b96d91284f1846ba1692715899514f9c5d6044dc55dc |