Files
scylladb/test/pylib/cpp/unit/unit_facade.py
Andrei Chekun 5f6740c1fa test.py: switch using f-string instead format in facades
Switching to f-string formatting to simplify the code and to unify it with a general approach for formatting strings.
2025-06-02 12:16:47 +02:00

56 lines
1.7 KiB
Python

#
# Copyright (C) 2025-present ScyllaDB
#
# SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
#
from __future__ import annotations
import os
from pathlib import Path
from typing import Sequence
import allure
from test.pylib.cpp.facade import CppTestFacade, CppTestFailure
class UnitTestFacade(CppTestFacade):
def list_tests(
self,
executable: Path,
no_parallel_run: bool,
mode: str
) -> tuple[bool, list[str]]:
return False, [os.path.basename(os.path.splitext(executable)[0])]
def run_test(
self,
executable: Path,
original_name: str,
test_name: str,
mode: str,
file_name: Path,
test_args: Sequence[str] = (),
env: dict = None,
) -> tuple[list[CppTestFailure], str] | tuple[None, str]:
args = [str(executable), *test_args]
test_passed, stdout_file_path, return_code = self.run_process(test_name, mode, file_name, args, env)
if not test_passed:
allure.attach(stdout_file_path.read_bytes(), name='output', attachment_type=allure.attachment_type.TEXT)
msg = (
f'working_dir: {os.getcwd()}\n'
f'Internal Error: calling {executable} '
f'for test {test_name} failed ({return_code=}):\n'
f'output:{stdout_file_path.absolute()}\n'
f'command to repeat:{" ".join(args)}'
)
failure = CppTestFailure(
file_name.name,
line_num=0,
contents=msg
)
return [failure], ''
stdout_file_path.unlink(missing_ok=True)
return None, ''