pytest-check
A pytest plugin that allows multiple failures per test.
This pytest plugin was a rewrite and a rename of pytest-expect.
Installation
From PPI:
$ pip install pytest-check
Or from github.
$ pip install git+https://github.com/okken/pytest-check
Usage
Example using import:
import pytest_check as check
def test_example():
a = 1
b = 2
c = [2, 4, 6]
check.greater(a, b)
check.less_equal(b, a)
check.is_in(a, c, "Is 1 in the list")
check.is_not_in(b, c, "make sure 2 isn't in list")
Test results:
=================================== FAILURES ===================================
_________________________________ test_example _________________________________
FAILURE:
assert 1 > 2
test_check.py, line 14, in test_example() -> check.greater(a, b)
FAILURE:
assert 2 <= 1
test_check.py, line 15, in test_example() -> check.less_equal(b, a)
FAILURE: Is 1 in the list
assert 1 in [2, 4, 6]
test_check.py, line 16, in test_example() -> check.is_in(a, c, "Is 1 in the list")
FAILURE: make sure 2 isn't in list
assert 2 not in [2, 4, 6]
test_check.py, line 17, in test_example() -> check.is_not_in(b, c, "make sure 2 isn't in list")
------------------------------------------------------------
Failed Checks: 4
=========================== 1 failed in 0.11 seconds ===========================
Example using fixture:
def test_example(check):
a = 1
b = 2
c = [2, 4, 6]
check.greater(a, b)
check.less_equal(b, a)
check.is_in(a, c, "Is 1 in the list")
check.is_not_in(b, c, "make sure 2 isn't in list")
validation functions
- check.equal - a == b
- check.not_equal - a != b
- check.is_true - bool(x) is True
- check.is_false - bool(x) is False
- check.is_none - x is None
- check.is_not_none - x is not None
- check.is_in - a in b
- check.not_in - a not in b
- check.is_instance - isinstance(a, b)
- check.not_is_instance - not isinstance(a, b)
- check.almost_equal - a == pytest.approx(b, rel, abs) see at: pytest.approx
- check.not_almost_equal - a != pytest.approx(b, rel, abs) see at: pytest.approx
- check.greater - a > b
- check.greater_equal - a >= b
- check.less - a < b
- check.less_equal - a <= b
Defining your own check functions
The @check_func decorator allows you to wrap any test helper that has an assert
statement in it to be a non-blocking assert function.
from pytest_check import check_func
@check_func
def is_four(a):
assert a == 4
def test_all_four():
is_four(1)
is_four(2)
is_four(3)
is_four(4)
The above will result in:
...
________________________________ test_all_four _________________________________
FAILURE: assert 1 == 4
test_fail.py, line 8, in test_all_four() -> is_four(1)
FAILURE: assert 2 == 4
test_fail.py, line 9, in test_all_four() -> is_four(2)
FAILURE: assert 3 == 4
test_fail.py, line 10, in test_all_four() -> is_four(3)
------------------------------------------------------------
Failed Checks: 3
=========================== 1 failed in 0.12 seconds ===========================
Contributing
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
License
Distributed under the terms of the MIT license, "pytest-check" is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Metadata
Release files for pytest-check 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytest-check-0.3.2.tar.gz | 5.0 kB | Without provenance | Details for pytest-check-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytest_check-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for pytest_check-0.3.2-py3-none-any.whl |
Total release size: 10.5 kB
Release files / pytest-check-0.3.2.tar.gz
| Download URL | pytest-check-0.3.2.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2d302084f23e6784c7e184b79570eeaad00cd066f58c1ae03820cca6fea799f
|
|
BLAKE2b-256 checksum How to use checksums |
86b6a9cd594c1734d40dbe0d4a738824018dda8f6e9fe39db2df7aaa445c23e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
|
Release files / pytest_check-0.3.2-py3-none-any.whl
| Download URL | pytest_check-0.3.2-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17e6fecf994c1dbba775297410c27ffe249a9fa342951863fe8fa9dce0d70d34
|
|
BLAKE2b-256 checksum How to use checksums |
4ae0145c37932f7820ebdde49cb061ebcefd9595a1b05004effa5eca32082b51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.0
|
Security for pytest-check 0.3.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.