From 8d150518439c4a2ccfa213a6a3f2336d8a29fb84 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Mon, 19 May 2025 16:33:13 +0900 Subject: [PATCH 1/3] Add hook to catch exceptions in test_info.error to trigger pytest errors --- tests/conftest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 5d3632a762..502cfda162 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -446,6 +446,17 @@ 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": + # Capture exception in test_info + test_info.error = str(call.excinfo.value) + @pytest.fixture(scope="session") def split_comparison(request): -- GitLab From 9ccae1bdf291614a4ac267d1ace52afa3bc75923 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 3 Jun 2025 13:59:58 +0200 Subject: [PATCH 2/3] Exclude Skipped and Failed from exceptions triggering error --- tests/conftest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 502cfda162..e0a821d3f7 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, @@ -454,9 +455,10 @@ def pytest_runtest_makereport(item, call): test_info = item.funcargs.get("test_info", None) if call.excinfo is not None and report.when == "call": - # Capture exception in test_info - test_info.error = str(call.excinfo.value) - + # Make sure exception is not due to a skipped or failed test (allowed exceptions) + if call.excinfo.type not in [Skipped, Failed]: + # Capture exception in test_info + test_info.error = str(call.excinfo.value) @pytest.fixture(scope="session") def split_comparison(request): -- GitLab From 6c200ff1cc4efb4b4c13597275c2b71f24e45b26 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 3 Jun 2025 14:20:59 +0200 Subject: [PATCH 3/3] Add handling of xfail --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index e0a821d3f7..117eee835a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -456,7 +456,9 @@ def pytest_runtest_makereport(item, call): if call.excinfo is not None and report.when == "call": # Make sure exception is not due to a skipped or failed test (allowed exceptions) - if call.excinfo.type not in [Skipped, Failed]: + 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) -- GitLab