Skip to main content

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
  • is_exception
  • after_applying_is

Metadata

Release files for pytest-matchers 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-matchers 0.3.6
File Size Uploaded
pytest_matchers-0.3.6.tar.gz 15.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-matchers 0.3.6
File Interpreter ABI Platform
pytest_matchers-0.3.6-py3-none-any.whl Python 3 none any Details

Total release size: 47.9 kB

Release files / pytest_matchers-0.3.6.tar.gz

Download URL pytest_matchers-0.3.6.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8359d7b9a48790467a2b4cd9d2c103ee63e69a2cefcfbd115df0d2bdd2185a61
BLAKE2b-256 checksum
How to use checksums
a2fbc48819f34b7fd7982556e20bc0a6183b854ad5fa6473cbe029e47c8a9016
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / pytest_matchers-0.3.6-py3-none-any.whl

Download URL pytest_matchers-0.3.6-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6bacf4b9ea56cb82db20b6e4032ebcaf11b5b854b6d887639a31d4a2107e677
BLAKE2b-256 checksum
How to use checksums
1d71eb7f9de24f697d9b8b68730b37b879d5ee098184a061840678115d79305a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

0.3.6 This release

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page