Repository: ClickHouse/ClickHouse
File: ci/praktika/result.py (Python)

Code before:
        sw = Utils.Stopwatch()
        files = []
        if pytest_report_file:
            files.append(pytest_report_file)
        else:
            pytest_report_file = ResultTranslator.PYTEST_RESULT_FILE
        if logfile:
            files.append(logfile)

        with ContextManager.cd(cwd):
            # Construct the full pytest command with jsonl report
            full_command = f"pytest {command} --report-log={pytest_report_file}"
            if logfile:
                full_command += f" --log-file={logfile}"

            # Apply environment
            for key, value in (env or {}).items():
                print(f"Setting environment variable {key} to {value}")
                os.environ[key] = value

            if name is None:
                name = f"pytest_{command}"

            # Run pytest
            _res = Shell.get_output(full_command, verbose=True)
            print(f"Pytest command output:\n{_res}")
            test_result = ResultTranslator.from_pytest_jsonl(
                pytest_report_file=pytest_report_file
            )
            if "!!!!!!! xdist.dsession.Interrupted: session-timeout:" in _res:
                test_result.info = "session-timeout occurred during test execution"

        return Result.create_from(
            name=name,
            results=test_result.results,
            status=test_result.status,
            stopwatch=sw,
            info=test_result.info,
            files=files,
        )

    @classmethod
    def _filter_out_ok_results(cls, result_obj):
        if not result_obj.results:
            return result_obj

        filtered = []
        for r in result_obj.results:
            if not r.is_ok():
                filtered.append(cls._filter_out_ok_results(r))


Review comment (suggestion):
Storing and printing the entire pytest output could be memory-intensive for large test suites. Consider limiting the output size or only capturing it when necessary for timeout detection.
```suggestion
            # Avoid printing arbitrarily large pytest output to stdout/logs.
            max_output_chars = 10_000
            if len(_res) <= max_output_chars:
                print(f"Pytest command output:\n{_res}")
            else:
                print(
                    "Pytest command output (truncated to "
                    f"{max_output_chars} characters):\n{_res[:max_output_chars]}\n...[truncated]..."
                )
```

Code after:
        """
        sw = Utils.Stopwatch()
        files = []
        if pytest_report_file:
            files.append(pytest_report_file)
        else:
            pytest_report_file = ResultTranslator.PYTEST_RESULT_FILE

        with ContextManager.cd(cwd):
            # Construct the full pytest command with jsonl report
            full_command = f"pytest {command} --report-log={pytest_report_file}"
            if pytest_logfile:
                full_command += f" --log-file={pytest_logfile}"
                files.append(pytest_logfile)
            if logfile:
                files.append(logfile)

            # Apply environment
            for key, value in (env or {}).items():
                print(f"Setting environment variable {key} to {value}")
                os.environ[key] = value

            if name is None:
                name = f"pytest_{command}"

            # Run pytest
            Shell.run(full_command, log_file=logfile)
            test_result = ResultTranslator.from_pytest_jsonl(
                pytest_report_file=pytest_report_file
            )

        return Result.create_from(
            name=name,
            results=test_result.results,
            status=test_result.status,
            stopwatch=sw,
            info=test_result.info,
            files=files,
        )

    @classmethod
    def _filter_out_ok_results(cls, result_obj):
        if not result_obj.results:
            return result_obj

        filtered = []
        for r in result_obj.results:
            if not r.is_ok():
                filtered.append(cls._filter_out_ok_results(r))

        if len(filtered) == len(result_obj.results):