Skip to main content

Simplify tests with warning and exception cases.

Project description

pytest-maybe-context

Makes it a bit easier to write warning and exception checks along other cases.

from pytest import mark, raises, warns
from pytest_maybe_context import maybe_context, not_context

@mark.parametrize(('buffering', 'expected'), (
    (0, b'contents'),
    (1, warns(RuntimeWarning)),
    (.1, raises(TypeError))
))
def test_example(buffering, expected):
    with maybe_context(expected):
        file = open('file', 'rb', buffering)
    if not_context(expected):
        assert file.read() == expected

Installation

poetry add pytest-maybe-context --group dev

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_maybe_context-0.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

pytest_maybe_context-0-py3-none-any.whl (2.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest_maybe_context-0.tar.gz.

File metadata

  • Download URL: pytest_maybe_context-0.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for pytest_maybe_context-0.tar.gz
Algorithm Hash digest
SHA256 c5781e2166760380d4d3e28317b5b089cb2e27b6c8210d5d1ad6db28812f62dd
MD5 70d1ffde709c9cadc3dfb89c21883363
BLAKE2b-256 200317764a88b2231a3f1278fdf2ce03309dde0fdaf8b543b6e447ed829b8d3c

See more details on using hashes here.

File details

Details for the file pytest_maybe_context-0-py3-none-any.whl.

File metadata

  • Download URL: pytest_maybe_context-0-py3-none-any.whl
  • Upload date:
  • Size: 2.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-38-generic

File hashes

Hashes for pytest_maybe_context-0-py3-none-any.whl
Algorithm Hash digest
SHA256 237098a5a71ec7387ffadcd8f4c8c87875be05a02dbd8e424913ad66fce4f86b
MD5 d5289b4d1711bd0230dbe6111541e1b9
BLAKE2b-256 8e374b06329b1b2d3b38dfc262875f716ae2b08b241094d973c20e30e71f7166

See more details on using hashes here.

Supported by

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