pytest-raises
An implementation of pytest.raises as a pytest.mark fixture
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-raisesuv
uv add pytest-raisespoetry
poetry add pytest-raisesInstalling 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
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-reraiseCaptures exceptions raised in threads during…
permissive · top 15,000 on PyPI
pytest-lazy-fixtureAllows you to use pytest fixtures directly as…
permissive · top 15,000 on PyPI
flake8-pytest-styleA flake8 plugin that detects and reports style…
unclear · top 15,000 on PyPI
pytest-fail-slowA pytest plugin that marks tests as failed if…
permissive · top 15,000 on PyPI
pytest-checkA pytest plugin that allows tests to continue…
unclear · top 5,000 on PyPI
parametrizeProvides a `@parametrize` decorator that works…
permissive · top 15,000 on PyPI
pytest-runtime-xfailA pytest plugin that provides a `runtime_xfail`…
permissive · top 15,000 on PyPI
pytest-orderA pytest plugin that lets you control the order…
permissive · top 5,000 on PyPI
pytest-codeblocksA pytest plugin that automatically discovers…
permissive · top 15,000 on PyPI