Commit 9e96b65f authored by Jan Kiene's avatar Jan Kiene
Browse files

Merge branch 'ci/error-reporting-fix' into 'main'

[CI] fix error reporting in pytest html reports

See merge request !2621
parents 91dbe989 892a90f6
Loading
Loading
Loading
Loading
Loading
+16 −35
Original line number Diff line number Diff line
@@ -453,25 +453,21 @@ def dut_encoder_path(request) -> str:
def test_info(request):
    yield request

    # Check for errors during teardown to report error instead of failure
    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
        exc_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)
        if exc_type not in [Skipped, Failed] and not xfail:
            # pytest-html v4 (_is_error in basereport.py) only shows "Error" when
            # report.when is "setup", "teardown", or "collect" — never for "call".
            # Reclassify this call-phase crash as a setup-phase error so the HTML
            # report shows ERROR instead of FAILURE.
            report.when = "setup"


@pytest.fixture(scope="session")
@@ -680,19 +676,14 @@ class EncoderFrontend:
            stderr_str = textwrap.indent(self.stderr, prefix="\t")
            log_dbg_msg(f"{self._type} encoder stderr:\n{stderr_str}")
        if self.returncode:
            pytest.fail(
            raise RuntimeError(
                f"{self._type} encoder terminated with a non-0 return code: {self.returncode}"
            )
        if self.stderr and "UndefinedBehaviorSanitizer" in self.stderr:
            pytest.fail("Undefined Behaviour runtime error encountered")
            raise RuntimeError("Undefined Behaviour runtime error encountered")

    def _check_run(self):
        if self.returncode is not None:
            if self.returncode:
                pytest.fail(
                    f"{self._type} encoder terminated with a non-0 return code: {self.returncode}"
                )
        else:
        if self.returncode is None:
            logger.warning("%s encoder was set-up, but not run", self._type)
        # next assert is not OK since stderr contains messages even when encoding was successful
        # assert not self.stderr, self._type + " encoder stderr is not empty"
@@ -964,19 +955,14 @@ class DecoderFrontend:
            stderr_str = textwrap.indent(self.stderr, prefix="\t")
            log_dbg_msg(f"{self._type} decoder stderr:\n{stderr_str}")
        if self.returncode:
            pytest.fail(
            raise RuntimeError(
                f"{self._type} decoder terminated with a non-0 return code: {self.returncode}"
            )
        if self.stderr and "UndefinedBehaviorSanitizer" in self.stderr:
            pytest.fail("Undefined Behaviour runtime error encountered")
            raise RuntimeError("Undefined Behaviour runtime error encountered")

    def _check_run(self):
        if self.returncode is not None:
            if self.returncode:
                pytest.fail(
                    f"{self._type} decoder terminated with a non-0 return code: {self.returncode}"
                )
        else:
        if self.returncode is None:
            logger.warning("%s decoder was set-up, but not run", self._type)
        # next assert is not OK since stderr contains messages even when decoding was successful
        # assert not self.stderr, self._type + " decoder stderr is not empty"
@@ -1466,19 +1452,14 @@ class PostRendFrontend:
            stderr_str = textwrap.indent(self.stderr, prefix="\t")
            log_dbg_msg(f"{self._type} post-rend stderr:\n{stderr_str}")
        if self.returncode:
            pytest.fail(
            raise RuntimeError(
                f"{self._type} post-rend terminated with a non-0 return code: {self.returncode}"
            )
        if self.stderr and "UndefinedBehaviorSanitizer" in self.stderr:
            pytest.fail("Undefined Behaviour runtime error encountered")
            raise RuntimeError("Undefined Behaviour runtime error encountered")

    def _check_run(self):
        if self.returncode is not None:
            if self.returncode:
                pytest.fail(
                    f"{self._type} post-rend terminated with a non-0 return code: {self.returncode}"
                )
        else:
        if self.returncode is None:
            logger.warning("%s post-rend was set-up, but not run", self._type)
        # next assert is not OK since stderr contains messages even when decoding was successful
        # assert not self.stderr, self._type + " decoder stderr is not empty"