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

Code before:
        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))

        if len(filtered) == len(result_obj.results):
            return result_obj  # No filtering needed

        result_copy = copy.deepcopy(result_obj)

Review comment (refactor):
The timeout detection string is hardcoded and fragile. Consider extracting this as a constant at module level or checking for a more stable indicator (e.g., exit status or structured output).

Code after:
            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):
            return result_obj  # No filtering needed

        result_copy = copy.deepcopy(result_obj)
        result_copy.results = filtered