Skip to content

wrwrwr/pytest-maybe-context

Repository files navigation

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

About

Simplify tests with warning and exception cases.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages