From e5bff6dcf3cb33e6dfb97722e142961099c6021e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Wed, 14 Aug 2024 16:21:33 +0100 Subject: [PATCH] fix(pytest): handle failed setup Previously we would only handle skipped setups, we need to handle failed setups in cases of fixture lookup errors. See #37 --- neotest_python/pytest.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/neotest_python/pytest.py b/neotest_python/pytest.py index a34454c..a2371f3 100644 --- a/neotest_python/pytest.py +++ b/neotest_python/pytest.py @@ -5,6 +5,7 @@ from typing import Callable, Dict, List, Optional, Union import pytest from _pytest._code.code import ExceptionRepr from _pytest.terminal import TerminalReporter +from _pytest.fixtures import FixtureLookupErrorRepr from .base import NeotestAdapter, NeotestError, NeotestResult, NeotestResultStatus @@ -100,8 +101,9 @@ class NeotestResultCollector: outcome = yield report = outcome.get_result() - if report.when != "call" and not ( - report.outcome == "skipped" and report.when == "setup" + if not ( + report.when == "call" + or (report.when == "setup" and report.outcome in ("skipped", "failed")) ): return @@ -136,6 +138,13 @@ class NeotestResultCollector: errors.append( {"message": msg_prefix + error_message, "line": error_line} ) + elif isinstance(exc_repr, FixtureLookupErrorRepr): + errors.append( + { + "message": msg_prefix + exc_repr.errorstring, + "line": exc_repr.firstlineno, + } + ) else: # TODO: Figure out how these are returned and how to represent raise Exception(