Skip to content

Commit 4a0bb2f

Browse files
authored
Merge pull request #118 from OpenTestSolar/bugfix/pytest-fix-parse-case-bug
修复解析用例问题
2 parents 0b5264b + b634d52 commit 4a0bb2f

5 files changed

Lines changed: 56 additions & 7 deletions

File tree

‎pytest/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "testsolar-pytestx"
3-
version = "0.1.77"
3+
version = "0.1.78"
44
description = "Pytest tool for TestSolar"
55
authors = [
66
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},

‎pytest/src/testsolar_pytestx/converter.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ def selector_to_pytest(test_selector: str) -> str:
1414
if not testcase: # tests/hello_test.py
1515
return path
1616

17+
# 参数化用例的数据驱动标记:tests/hello_test.py?xxxTest/[data]
18+
# 只要出现 /[ 就说明该 selector 是一个真实的参数化用例节点,
19+
# 即使数据驱动数据中包含 "="(例如 sample_rate=0),也不应该被误判为属性筛选
20+
data_drive_flag = "/["
21+
1722
if "&" in testcase:
1823
testcase_attrs = testcase.split("&")
1924
for attr in testcase_attrs:
@@ -23,12 +28,20 @@ def selector_to_pytest(test_selector: str) -> str:
2328
elif "=" not in attr: # tests/hello_test.py?xxxTest&
2429
testcase = attr
2530
break
26-
else: # tests/hello_test.py?test_hello_world&tag=prod
27-
return path
31+
else:
32+
# 所有属性均包含 "=",无法区分属性筛选与参数化用例
33+
if data_drive_flag not in testcase:
34+
# 不含数据驱动标记,判定为纯属性筛选
35+
# tests/hello_test.py?test_hello_world&tag=prod
36+
return path
2837
else:
2938
if testcase.startswith("name="): # tests/hello_test.py?name=xxxTest
3039
testcase = testcase[5:]
31-
elif "=" in testcase: # tests/hello_test.py?tag=prod
40+
elif "=" in testcase and data_drive_flag not in testcase:
41+
# tests/hello_test.py?tag=prod
42+
# 注意:参数化数据中可能包含 "=",例如
43+
# tests/test_asr_websocket.py?TestAsrWebSocket/test_sample_rate_parametrized/[0-default-sample_rate=0-False]
44+
# 这种场景下数据驱动标记 /[ 一定存在,不能返回 path 导致退化为整个文件执行
3245
return path
3346

3447
case, datadrive = extract_case_and_datadrive(testcase)

‎pytest/tests/test_converter.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,42 @@ def test_selector_to_pytest_with_datadrive(self):
5454
"/data/tests/tests/test_data_drive_with_backslash.py::test_backslash[\\n]",
5555
)
5656

57+
def test_selector_to_pytest_with_equal_sign_in_datadrive(self):
58+
# 回归场景:参数化数据中包含 "=" 时,不能被误判为属性筛选而退化为整个文件执行
59+
re = selector_to_pytest(
60+
"tests/test_asr_websocket.py?TestAsrWebSocket/test_sample_rate_parametrized/[0-default-sample_rate=0-False]"
61+
)
62+
self.assertEqual(
63+
re,
64+
"tests/test_asr_websocket.py::TestAsrWebSocket::test_sample_rate_parametrized[0-default-sample_rate=0-False]",
65+
)
66+
67+
# 参数化数据同时包含 "=" 和中文全角括号
68+
re = selector_to_pytest(
69+
"tests/test_asr_websocket.py?TestAsrWebSocket/test_asr_context_type_parametrized/[no_context-type=no_context(无上下文)-False]"
70+
)
71+
self.assertEqual(
72+
re,
73+
"tests/test_asr_websocket.py::TestAsrWebSocket::test_asr_context_type_parametrized[no_context-type=no_context\\uff08\\u65e0\\u4e0a\\u4e0b\\u6587\\uff09-False]",
74+
)
75+
76+
re = selector_to_pytest(
77+
"tests/test_asr_websocket.py?TestAsrWebSocket/test_voice_id_parametrized/[aaaaaaaa-voice_id=129位(超限)-True]"
78+
)
79+
self.assertEqual(
80+
re,
81+
"tests/test_asr_websocket.py::TestAsrWebSocket::test_voice_id_parametrized[aaaaaaaa-voice_id=129\\u4f4d\\uff08\\u8d85\\u9650\\uff09-True]",
82+
)
83+
84+
def test_selector_to_pytest_with_equal_sign_in_http_datadrive(self):
85+
re = selector_to_pytest(
86+
"tests/test_asr_http.py?TestASRRecognize/test_recognize_audio_format/[summary_context-base64-pcm]"
87+
)
88+
self.assertEqual(
89+
re,
90+
"tests/test_asr_http.py::TestASRRecognize::test_recognize_audio_format[summary_context-base64-pcm]",
91+
)
92+
5793
def test_selector_to_pytest_with_utf8_string(self):
5894
re = selector_to_pytest(
5995
"/data/tests/tests/test_data_drive_zh_cn.py?aa/bb/test_include/[中文-中文汉字]"

‎pytest/testtool.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ schemaVersion: 1.0
22
name: pytest
33
nameZh: pytest自动化测试
44
lang: python
5-
version: '0.1.77'
5+
version: '0.1.78'
66
langType: INTERPRETED
77
description: |-
88
pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。

‎pytest/uv.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)