All Projects → okken → Pytest Check

okken / Pytest Check

Licence: mit
A pytest plugin that allows multiple failures per test.

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to Pytest Check

Pytest Spec
Library pytest-spec is a pytest plugin to display test execution output like a SPECIFICATION.
Stars: ✭ 65 (-50.38%)
Mutual labels:  pytest
Pytest Deadfixtures
Plugin to list unused fixtures in your tests
Stars: ✭ 89 (-32.06%)
Mutual labels:  pytest
Wagtail Pipit
Pipit is a Wagtail CMS boilerplate which aims to provide an easy and modern developer workflow with a React-rendered frontend.
Stars: ✭ 109 (-16.79%)
Mutual labels:  pytest
Syrupy
🥞 The sweeter pytest snapshot plugin
Stars: ✭ 73 (-44.27%)
Mutual labels:  pytest
Pytest Instafail
py.test plugin to show failures instantly
Stars: ✭ 86 (-34.35%)
Mutual labels:  pytest
Pytest Cookies
The pytest plugin for your Cookiecutter templates. 🍪
Stars: ✭ 96 (-26.72%)
Mutual labels:  pytest
Pytest Grpc
Allow test gRPC with pytest
Stars: ✭ 63 (-51.91%)
Mutual labels:  pytest
Python Pytest Cases
Separate test code from test cases in pytest.
Stars: ✭ 127 (-3.05%)
Mutual labels:  pytest
Pytest Regressions
Pytest plugin for regression testing: https://pytest-regressions.readthedocs.io
Stars: ✭ 89 (-32.06%)
Mutual labels:  pytest
Pytest Monitor
Pytest plugin for analyzing resource usage during test sessions
Stars: ✭ 105 (-19.85%)
Mutual labels:  pytest
Flake8 Pytest Style
A flake8 plugin checking common style issues or inconsistencies with pytest-based tests.
Stars: ✭ 74 (-43.51%)
Mutual labels:  pytest
Education Backend
Django backend for my info-business website
Stars: ✭ 79 (-39.69%)
Mutual labels:  pytest
Pytest Repeat
pytest plugin for repeating test execution
Stars: ✭ 99 (-24.43%)
Mutual labels:  pytest
Molecule Ansible Docker Aws
Example project showing how to test Ansible roles with Molecule using Testinfra and a multiscenario approach with Docker, Vagrant & AWS EC2 as infrastructure providers
Stars: ✭ 72 (-45.04%)
Mutual labels:  pytest
Kubetest
Kubernetes integration testing in Python via pytest
Stars: ✭ 122 (-6.87%)
Mutual labels:  pytest
Wemake Django Template
Bleeding edge django template focused on code quality and security.
Stars: ✭ 1,141 (+770.99%)
Mutual labels:  pytest
Frost
Unit testing framework for test driven security of AWS, GCP, Heroku and more.
Stars: ✭ 91 (-30.53%)
Mutual labels:  pytest
Pytest Describe
Describe-style plugin for the pytest framework
Stars: ✭ 128 (-2.29%)
Mutual labels:  pytest
Python Blueprint
🐍 Example Python project using best practices 🔩
Stars: ✭ 123 (-6.11%)
Mutual labels:  pytest
Pytest Recording
A pytest plugin that allows recording network interactions via VCR.py
Stars: ✭ 98 (-25.19%)
Mutual labels:  pytest

pytest-check

A pytest plugin that allows multiple failures per test.


This pytest plugin was a rewrite and a rename of pytest-expect.

Installation

Note: Requires pytest 6.0 or above.

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_ - a is b
  • check.is_not - a is not 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.is_not_in - a not in b
  • check.is_instance - isinstance(a, b)
  • check.is_not_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 ===========================

Using check as a context manager

You can use the check() context manager to wrap any assert that you want to continue after in a test.

from pytest_check import check


def test_context_manager():
    with check:
        x = 3
        assert 1 < x < 4

Within any with check:, however, you still won't get past the assert statement, so you will need to use multiple with check: blocks for multiple asserts:

    def test_multiple_failures():
        with check: assert 1 == 0
        with check: assert 1 > 2
        with check: assert 1 < 5 < 4

Contributing

Contributions are very welcome. Tests can be run with tox. Test coverage is now 100%. Please make sure to keep it at 100%. If you have an awesome pull request and need help with getting coverage back up, let me know.

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.

Changelog

  • 1.0.1
    • Remove Beta Classifier
    • Status is now "Development Status :: 5 - Production/Stable"
  • 1.0.0
    • Jump to 1.0 version, API is fairly stable.
  • 0.4.1
    • Fix #43/#44 tests with failing checks and failing asserts now report all issues.
  • 0.4.0
    • added is_() and is_not()
    • Requires pytest 6.0 or above. (Removed some cruft to support pytest 5.x)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].