{"library":"pytest-reraise","title":"pytest-reraise","description":"pytest-reraise is a pytest plugin designed to make multi-threaded test cases fail when exceptions occur in background threads. Without it, exceptions in threads separate from the main test thread might not be caught by pytest, leading to silently passing tests. The current version is 2.1.2, with a release cadence that focuses on bug fixes and minor feature enhancements.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pytest-reraise"],"cli":{"name":"pytest","version":"pytest 9.0.3"}},"imports":["from pytest_reraise import Reraise"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import threading\nfrom pytest_reraise import Reraise\nimport pytest\n\ndef test_threaded_exception_is_caught():\n    # This test will fail due to the ValueError in the thread\n    # because pytest-reraise ensures the exception is re-raised.\n    \n    # Option 1: Instantiate Reraise\n    reraise_instance = Reraise()\n    def func_with_error():\n        raise ValueError(\"This exception should fail the test!\")\n\n    thread_with_error = threading.Thread(target=reraise_instance.wrap(func_with_error))\n    thread_with_error.start()\n    thread_with_error.join()\n\n    # Option 2: Use the class method (introduced in v2.1.0)\n    def another_func_with_error():\n        # Example of a division by zero\n        _ = 1 / 0\n    \n    thread_with_another_error = threading.Thread(target=Reraise.wrap(another_func_with_error))\n    thread_with_another_error.start()\n    thread_with_another_error.join()\n\n# To run this example:\n# 1. Save it as `test_example.py`\n# 2. Run `pytest test_example.py` in your terminal.\n# Expected outcome: Both parts of the test will raise exceptions and cause the test to fail.","lang":"python","description":"This quickstart demonstrates how to use `pytest-reraise` to catch exceptions that occur in background threads. Without `Reraise.wrap()`, `pytest` would typically miss these exceptions, allowing the test to pass even if a critical error occurred in a non-main thread.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}