diff --git a/tests/conftest.py b/tests/conftest.py index 5d3632a762c2818b21363114c83a964b5b5ece90..117eee835a263eea1c461daa88325939d32a6217 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -47,6 +47,7 @@ from shutil import move import tempfile from typing import Optional, Union, List import numpy as np +from _pytest.outcomes import Skipped, Failed from .constants import ( DMX_DIFF, DMX_MLD, @@ -446,6 +447,20 @@ def test_info(request): if hasattr(request, "error"): pytest.fail(request.error) +@pytest.hookimpl(hookwrapper=True) +def pytest_runtest_makereport(item, call): + # Use hook to catch exceptions + outcome = yield + report = outcome.get_result() + test_info = item.funcargs.get("test_info", None) + + if call.excinfo is not None and report.when == "call": + # Make sure exception is not due to a skipped or failed test (allowed exceptions) + type = call.excinfo.type + xfail = hasattr(report, "wasxfail") + if type not in [Skipped, Failed] and not xfail: + # Capture exception in test_info + test_info.error = str(call.excinfo.value) @pytest.fixture(scope="session") def split_comparison(request):