From a102a0c19721a8d8626ebd5bb43cb9073125661c Mon Sep 17 00:00:00 2001 From: zixingdeng Date: Thu, 22 Jan 2026 16:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E6=89=93=E5=8D=B0=E5=89=8D=E5=85=88?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytest/pyproject.toml | 2 +- pytest/src/testsolar_pytestx/stream.py | 26 +++++++++++++++++--------- pytest/testtool.yaml | 2 +- pytest/uv.lock | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/pytest/pyproject.toml b/pytest/pyproject.toml index 7d9317b..9b8f9b3 100644 --- a/pytest/pyproject.toml +++ b/pytest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testsolar-pytestx" -version = "0.1.75" +version = "0.1.76" description = "Pytest tool for TestSolar" authors = [ {name = "asiazhang2002", email = "asiazhang2002@gmail.com"}, diff --git a/pytest/src/testsolar_pytestx/stream.py b/pytest/src/testsolar_pytestx/stream.py index 31895c6..e8ade32 100644 --- a/pytest/src/testsolar_pytestx/stream.py +++ b/pytest/src/testsolar_pytestx/stream.py @@ -2,7 +2,7 @@ import sys import pytest import contextlib -from typing import List, Tuple, TextIO, TypeVar +from typing import List, Tuple, TextIO, TypeVar, Union T = TypeVar("T") @@ -27,14 +27,22 @@ class TeeStream: def __init__(self, *streams: TextIO) -> None: self.streams = streams - def write(self, data: str) -> None: - for stream in self.streams: - # 如果是标准输出流/标准错误流则直接写入 - if not isinstance(stream, io.StringIO): - stream.write(data) - # 若超过最大字符数则不写入,避免内存占用过高 - elif not exceeds_max_size(stream=stream): - stream.write(data) + def write(self, data: Union[str, bytes]) -> None: + try: + # 确保 data 是字符串类型 + if isinstance(data, bytes): + data = data.decode("utf-8", errors="replace") + + for stream in self.streams: + # 如果是标准输出流/标准错误流则直接写入 + if not isinstance(stream, io.StringIO): + stream.write(data) + # 若超过最大字符数则不写入,避免内存占用过高 + elif not exceeds_max_size(stream=stream): + stream.write(data) + except Exception: + # 捕获所有异常,避免写入失败导致程序崩溃 + pass def flush(self) -> None: for stream in self.streams: diff --git a/pytest/testtool.yaml b/pytest/testtool.yaml index 13d4e65..8adab16 100644 --- a/pytest/testtool.yaml +++ b/pytest/testtool.yaml @@ -2,7 +2,7 @@ schemaVersion: 1.0 name: pytest nameZh: pytest自动化测试 lang: python -version: '0.1.75' +version: '0.1.76' langType: INTERPRETED description: |- pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。 diff --git a/pytest/uv.lock b/pytest/uv.lock index e0c3c50..2baad39 100644 --- a/pytest/uv.lock +++ b/pytest/uv.lock @@ -463,7 +463,7 @@ wheels = [ [[package]] name = "testsolar-pytestx" -version = "0.1.73" +version = "0.1.75" source = { virtual = "." } dependencies = [ { name = "coverage" },