skillfed

pytest-reraise

Make multi-threaded pytest test cases fail when they should

pytest-reraise v2.1.2 180.4K downloads/30d#10,145 on PyPI20
Permissive license MIT Abandoned released

What it is and what it does

pytest-reraise is a pytest plugin that solves a specific threading problem: when you write assertions inside a thread spawned from a test, those assertions fail silently because the exception is raised in the thread, not the main test thread. The plugin provides a `reraise` fixture that acts as a context manager to capture exceptions from worker threads and re-raise them in the main thread at the end of the test, making the test fail as expected.

The plugin supports wrapping functions as decorators, manually triggering re-raises mid-test, handling multiple exceptions (keeping the first), optionally catching exceptions to prevent them from crashing the thread, and accessing or resetting captured exceptions. It's designed for developers writing multi-threaded tests who need pytest to properly detect assertion failures that occur in spawned threads.

Use it for:

  • Testing concurrent code where worker threads perform assertions that must be validated by the main test
  • Verifying that background tasks or thread pools fail correctly when they encounter errors
  • Debugging multi-threaded applications by ensuring thread exceptions don't silently pass tests
  • Wrapping thread target functions with exception capture to keep threads alive while collecting errors
  • Comparing captured thread exceptions against expected error types or messages in test assertions

Worth the install?

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

Captures exceptions raised in threads during pytest tests and re-raises them in the main thread so that multi-threaded test failures are properly detected.

Yes, if you actively write multi-threaded pytest tests and need thread exceptions to fail your tests. The low install friction and permissive license make adoption easy. However, the abandoned maintenance status (last commit 2023-02-06) is a concern—verify compatibility with your pytest and Python versions before relying on it for new projects, and monitor for any unresolved issues with newer releases.

Install

pytest-reraise on PyPI

pip

pip install pytest-reraise

uv

uv add pytest-reraise

poetry

poetry add pytest-reraise

Installing pytest-reraise

Before you install

Low friction: pure Python wheel with only pytest as a runtime dependency. Maintenance is stalled—last commit was 2023-02-06 and the package is marked abandoned, though it remains marked Production/Stable and has received no security reports.

License in practice

MIT license is permissive; you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.

Quickstart

pip install pytest-reraise

# In your test file:
from threading import Thread

def test_with_thread(reraise):
    def run():
        with reraise:
            assert False
    Thread(target=run).start()

Verify before relying

  • Whether the package works reliably with pytest versions released after 2023-02-06
  • Whether the abandoned status indicates unresolved bugs or compatibility issues with newer Python or pytest releases

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.6.1,<4.0.0)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pytest
Maintenance abandoned — 1,424 days since the last release
Last repo commit
First released
Downloads 180,427/month — #10,145 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_reraise-2.1.2-py3-none-any.whl

Keywords: pytest, plugin, threads, exception, assert, catch, raise, re-raise

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTyping :: Typed

Tags

pytest thread exception handlingmulti-threaded test assertionscapture exceptions in threadspytest plugin threadingthread assertion failurespytest reraise decoratortest thread error detection
pytest-pluginthreadingtest-utilities

More Libraries packages