Skip to main content

Matchers for pytest

Project description

Pytest Matchers

Test your code with vague constrains

Release Notes CI PyPI - License PyPI - Downloads GitHub star chart Code style: black

Quick Install

With pip

pip install pytest-matchers

With poetry

poetry add pytest-matchers [--group dev]

Usage

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

Matchers

  • 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_matchers-0.3.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_matchers-0.3.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_matchers-0.3.1.tar.gz.

File metadata

  • Download URL: pytest_matchers-0.3.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for pytest_matchers-0.3.1.tar.gz
Algorithm Hash digest
SHA256 2f1426592c876972213f3fa8d03189768ea61b1f879e0eb0d7fe22472ac451bd
MD5 483460c837cce1a70ebb6928967110bd
BLAKE2b-256 06fe0378e4125c6a7f4a66125643f63a0ee3f44dac045054bd8ab704f636826a

See more details on using hashes here.

File details

Details for the file pytest_matchers-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_matchers-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 98adb034758b13c3f0702a1bb412fe1969418b2e6fc802032033fec20e29a895
MD5 e84ffa5b4df37a86d0bce5c1b01ce2ce
BLAKE2b-256 88b80df61e668960e84d8f73850a0db9a76fa7939a13ff34d2c843993eee837e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page