Test your code with vague constrains
With pip
pip install pytest-matchers
With poetry
poetry add pytest-matchers [--group dev]
Examples on tests/examples
from random import random
from pytest_matchers import is_number
def test_random_number():
assert random() == is_number(min_value=0, max_value=1)
And when failing:
def test_random_number():
assert random() == is_number(min_value=1, max_value=2)
On pytest CLI
=================================== FAILURES ===================================
______________________________ test_random_number ______________________________
def test_random_number():
> assert random() == is_number(min_value=1, max_value=2)
E assert 0.9048172867693559 == To be a number between 1 and 2
E + where 0.9048172867693559 = random()
E + and To be a number between 1 and 2 = is_number(min_value=1, max_value=2)
tests/examples/test_example.py:6: AssertionError
=========================== short test summary info ============================
FAILED tests/examples/test_example.py::test_random_number - assert 0.9048172867693559 == To be a number between 1 and 2
============================== 1 failed in 0.02s ===============================
On PyCharm
tests/examples/test_example.py:4 (test_random_number)
0.9048172867693559 != To be a number between 1 and 2
Expected :To be a number between 1 and 2
Actual :0.9048172867693559
is_number
is_string
is_list
is_instance
between
one_of
has_attribute
is_datetime
is_datetime_string
same_value
different_value
if_true
if_false
case
is_dict
is_strict_dict
is_json
is_uuid