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
This commit is contained in:
Rónán Carrigan
2024-08-14 16:21:33 +01:00
parent 0ab9ad3570
commit e5bff6dcf3

View File

@@ -5,6 +5,7 @@ from typing import Callable, Dict, List, Optional, Union
import pytest import pytest
from _pytest._code.code import ExceptionRepr from _pytest._code.code import ExceptionRepr
from _pytest.terminal import TerminalReporter from _pytest.terminal import TerminalReporter
from _pytest.fixtures import FixtureLookupErrorRepr
from .base import NeotestAdapter, NeotestError, NeotestResult, NeotestResultStatus from .base import NeotestAdapter, NeotestError, NeotestResult, NeotestResultStatus
@@ -100,8 +101,9 @@ class NeotestResultCollector:
outcome = yield outcome = yield
report = outcome.get_result() report = outcome.get_result()
if report.when != "call" and not ( if not (
report.outcome == "skipped" and report.when == "setup" report.when == "call"
or (report.when == "setup" and report.outcome in ("skipped", "failed"))
): ):
return return
@@ -136,6 +138,13 @@ class NeotestResultCollector:
errors.append( errors.append(
{"message": msg_prefix + error_message, "line": error_line} {"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: else:
# TODO: Figure out how these are returned and how to represent # TODO: Figure out how these are returned and how to represent
raise Exception( raise Exception(