From b634d528c15d83613e4a2bfbb50860613d48cc2c Mon Sep 17 00:00:00 2001 From: zixingdeng Date: Fri, 7 Aug 2026 10:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=A3=E6=9E=90=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pytest/pyproject.toml | 2 +- pytest/src/testsolar_pytestx/converter.py | 19 ++++++++++-- pytest/tests/test_converter.py | 36 +++++++++++++++++++++++ pytest/testtool.yaml | 2 +- pytest/uv.lock | 4 +-- 5 files changed, 56 insertions(+), 7 deletions(-) diff --git a/pytest/pyproject.toml b/pytest/pyproject.toml index c88b12f..5aeec76 100644 --- a/pytest/pyproject.toml +++ b/pytest/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "testsolar-pytestx" -version = "0.1.77" +version = "0.1.78" description = "Pytest tool for TestSolar" authors = [ {name = "asiazhang2002", email = "asiazhang2002@gmail.com"}, diff --git a/pytest/src/testsolar_pytestx/converter.py b/pytest/src/testsolar_pytestx/converter.py index 78f22c0..2f963d2 100644 --- a/pytest/src/testsolar_pytestx/converter.py +++ b/pytest/src/testsolar_pytestx/converter.py @@ -14,6 +14,11 @@ def selector_to_pytest(test_selector: str) -> str: if not testcase: # tests/hello_test.py return path + # 参数化用例的数据驱动标记:tests/hello_test.py?xxxTest/[data] + # 只要出现 /[ 就说明该 selector 是一个真实的参数化用例节点, + # 即使数据驱动数据中包含 "="(例如 sample_rate=0),也不应该被误判为属性筛选 + data_drive_flag = "/[" + if "&" in testcase: testcase_attrs = testcase.split("&") for attr in testcase_attrs: @@ -23,12 +28,20 @@ def selector_to_pytest(test_selector: str) -> str: elif "=" not in attr: # tests/hello_test.py?xxxTest& testcase = attr break - else: # tests/hello_test.py?test_hello_world&tag=prod - return path + else: + # 所有属性均包含 "=",无法区分属性筛选与参数化用例 + if data_drive_flag not in testcase: + # 不含数据驱动标记,判定为纯属性筛选 + # tests/hello_test.py?test_hello_world&tag=prod + return path else: if testcase.startswith("name="): # tests/hello_test.py?name=xxxTest testcase = testcase[5:] - elif "=" in testcase: # tests/hello_test.py?tag=prod + elif "=" in testcase and data_drive_flag not in testcase: + # tests/hello_test.py?tag=prod + # 注意:参数化数据中可能包含 "=",例如 + # tests/test_asr_websocket.py?TestAsrWebSocket/test_sample_rate_parametrized/[0-default-sample_rate=0-False] + # 这种场景下数据驱动标记 /[ 一定存在,不能返回 path 导致退化为整个文件执行 return path case, datadrive = extract_case_and_datadrive(testcase) diff --git a/pytest/tests/test_converter.py b/pytest/tests/test_converter.py index 6702f8f..f459445 100644 --- a/pytest/tests/test_converter.py +++ b/pytest/tests/test_converter.py @@ -54,6 +54,42 @@ def test_selector_to_pytest_with_datadrive(self): "/data/tests/tests/test_data_drive_with_backslash.py::test_backslash[\\n]", ) + def test_selector_to_pytest_with_equal_sign_in_datadrive(self): + # 回归场景:参数化数据中包含 "=" 时,不能被误判为属性筛选而退化为整个文件执行 + re = selector_to_pytest( + "tests/test_asr_websocket.py?TestAsrWebSocket/test_sample_rate_parametrized/[0-default-sample_rate=0-False]" + ) + self.assertEqual( + re, + "tests/test_asr_websocket.py::TestAsrWebSocket::test_sample_rate_parametrized[0-default-sample_rate=0-False]", + ) + + # 参数化数据同时包含 "=" 和中文全角括号 + re = selector_to_pytest( + "tests/test_asr_websocket.py?TestAsrWebSocket/test_asr_context_type_parametrized/[no_context-type=no_context(无上下文)-False]" + ) + self.assertEqual( + re, + "tests/test_asr_websocket.py::TestAsrWebSocket::test_asr_context_type_parametrized[no_context-type=no_context\\uff08\\u65e0\\u4e0a\\u4e0b\\u6587\\uff09-False]", + ) + + re = selector_to_pytest( + "tests/test_asr_websocket.py?TestAsrWebSocket/test_voice_id_parametrized/[aaaaaaaa-voice_id=129位(超限)-True]" + ) + self.assertEqual( + re, + "tests/test_asr_websocket.py::TestAsrWebSocket::test_voice_id_parametrized[aaaaaaaa-voice_id=129\\u4f4d\\uff08\\u8d85\\u9650\\uff09-True]", + ) + + def test_selector_to_pytest_with_equal_sign_in_http_datadrive(self): + re = selector_to_pytest( + "tests/test_asr_http.py?TestASRRecognize/test_recognize_audio_format/[summary_context-base64-pcm]" + ) + self.assertEqual( + re, + "tests/test_asr_http.py::TestASRRecognize::test_recognize_audio_format[summary_context-base64-pcm]", + ) + def test_selector_to_pytest_with_utf8_string(self): re = selector_to_pytest( "/data/tests/tests/test_data_drive_zh_cn.py?aa/bb/test_include/[中文-中文汉字]" diff --git a/pytest/testtool.yaml b/pytest/testtool.yaml index 3f2777b..782c684 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.77' +version: '0.1.78' langType: INTERPRETED description: |- pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。 diff --git a/pytest/uv.lock b/pytest/uv.lock index 2baad39..71bdd35 100644 --- a/pytest/uv.lock +++ b/pytest/uv.lock @@ -1,5 +1,5 @@ version = 1 -revision = 2 +revision = 3 requires-python = ">=3.7" [[package]] @@ -463,7 +463,7 @@ wheels = [ [[package]] name = "testsolar-pytestx" -version = "0.1.75" +version = "0.1.78" source = { virtual = "." } dependencies = [ { name = "coverage" },