skillfed

pytest-raises

An implementation of pytest.raises as a pytest.mark fixture

pytest-raises v0.11 159.7K downloads/30d#10,691 on PyPI20
License unclear DORMANT released

What it is and what it does

pytest-raises is a pytest plugin that lets you mark test functions with decorators to assert they raise expected exceptions. Instead of wrapping code in a `with pytest.raises(...)` context manager, you decorate the entire test function with `@pytest.mark.raises()` or `@pytest.mark.setup_raises()` to declare that an exception should be raised during test execution or setup, respectively. The plugin accepts optional parameters to specify the exception type, match the exception message by substring or regex, and apply regex flags.

The main use case is marking tests (especially in parametrized test suites) where raising an exception is the expected behavior—the test passes only if the exception is raised. It also provides `@pytest.mark.setup_raises()` for the uncommon case where you need to verify that an exception occurs during pytest's setup phase rather than during the test itself. The package depends only on pytest and installs with low friction, but has been dormant since 2020 with no recent maintenance.

Use it for:

  • Mark parametrized test cases where different parameters should raise different exception types, using pytest.param with the marker.
  • Assert that fixture setup or custom pytest hooks raise expected errors during the pytest_runtest_setup phase.
  • Replace verbose `with pytest.raises(...)` blocks with a cleaner decorator syntax for entire test functions.
  • Verify that code raises a specific exception type with a message matching a regex pattern or substring.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides pytest markers (@pytest.mark.raises and @pytest.mark.setup_raises) to assert that test code raises expected exceptions, functioning as a decorator alternative to pytest.raises context managers.

Yes, if you are already on pytest 2.8.1+ and want decorator-based exception assertions instead of context managers. However, exercise caution: the package is dormant (last release 2020-04-23), so compatibility with modern pytest versions is unverified, and the license is unclear. Test it in a non-critical project first, or consider whether the built-in `with pytest.raises(...)` context manager meets your needs instead.

Install

pytest-raises on PyPI

pip

pip install pytest-raises

uv

uv add pytest-raises

poetry

poetry add pytest-raises

Installing pytest-raises

Before you install

Low install friction with a single pytest dependency. Package is dormant (last release 2020-04-23, no commits since 2023-09-29), so expect no active maintenance or updates.

License in practice

License treatment is unclear—no SPDX identifier or raw license text provided in metadata, making legal terms ambiguous for redistribution or modification.

Quickstart

pip install pytest-raises

import pytest

@pytest.mark.raises(exception=ValueError)
def test_something():
    raise ValueError('expected error')

Requires pytest 2.8.1 or above; test function body with @pytest.mark.setup_raises must be exactly 'pass' (no other code allowed).

Verify before relying

  • Whether the package is compatible with modern pytest versions (last release was 2020-04-23).
  • Actual Python version support range—metadata lists 'python 2.7 or above' but requires_python is empty.
  • Whether dormant status and lack of recent commits indicate compatibility issues with current test frameworks.

Package facts

License not declared (unclear)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance dormant — 2,304 days since the last release
Last repo commit
First released
Downloads 159,704/month — #10,691 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_raises-0.11-py2.py3-none-any.whl

Tags

pytest exception assertion decoratorpytest mark raises plugintest expected exceptions pytestpytest raises markerassert exception raised pytestpytest setup phase exception testing
pytest-pluginexception-testing

More Testing packages