Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pytest/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"},
Expand Down
19 changes: 16 additions & 3 deletions pytest/src/testsolar_pytestx/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
36 changes: 36 additions & 0 deletions pytest/tests/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/[中文-中文汉字]"
Expand Down
2 changes: 1 addition & 1 deletion pytest/testtool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down
4 changes: 2 additions & 2 deletions pytest/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading