Files
scylladb/test/pylib/cpp/unit.py
Andrei Chekun 767789304e test.py: improve C++ fail summary in pytest
Currently, if the test fail, pytest will output only some basic information
about the fail. With this change, it will output the last 300 lines of the
boost/seastar test output.
Also add capturing the output of the failed tests to JUnit report, so it
will be present in the report on Jenkins.

Fixes: https://scylladb.atlassian.net/browse/SCYLLADB-449

Closes scylladb/scylladb#28535
2026-02-17 14:25:28 +03:00

48 lines
1.5 KiB
Python

#
# Copyright (C) 2025-present ScyllaDB
#
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
#
from __future__ import annotations
import os
import subprocess
from pathlib import Path
from textwrap import dedent
from typing import TYPE_CHECKING
import allure
from test.pylib.cpp.base import CppFile, CppTestFailure
if TYPE_CHECKING:
from test.pylib.cpp.base import CppTestCase
class UnitTestFile(CppFile):
def list_test_cases(self) -> list[str]:
return [self.test_name]
def run_test_case(self, test_case: CppTestCase) -> tuple[list[CppTestFailure], Path] | tuple[None, Path]:
stdout_file_path = test_case.get_artifact_path(extra="_stdout", suffix=".log").absolute()
process = test_case.run_exe(test_args=self.test_args, output_file=stdout_file_path)
if return_code := process.returncode:
allure.attach(stdout_file_path.read_bytes(), name="output", attachment_type=allure.attachment_type.TEXT)
return [CppTestFailure(
file_name=self.path.name,
line_num=0,
content=dedent(f"""\
working_dir: {os.getcwd()}
Internal Error: calling {self.exe_path} for test {test_case.test_case_name} failed ({return_code=}):
output file: {stdout_file_path}
command to repeat: {subprocess.list2cmdline(process.args)}
"""),
)], stdout_file_path
return None, stdout_file_path
pytest_collect_file = UnitTestFile.pytest_collect_file