Skip to content

Commit 93e4d1a

Browse files
authored
Merge pull request #93 from OpenTestSolar/dev/support-encode-test-name
支持对用例名进行编码
2 parents d770f54 + 8622971 commit 93e4d1a

7 files changed

Lines changed: 30 additions & 18 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.37"
3+
version = "0.1.38"
44
description = "Pytest tool for TestSolar"
55
authors = [
66
{name = "asiazhang2002", email = "asiazhang2002@gmail.com"},

‎pytest/src/testsolar_pytestx/converter.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import os
33
from typing import Tuple, Optional
4-
4+
from urllib.parse import quote
55
from pytest import Item
66
from loguru import logger
77

@@ -79,14 +79,18 @@ def pytest_to_selector(item: Item, project_path: str) -> str:
7979
if item.cls:
8080
name = item.cls.__name__ + "/" + name
8181
name = decode_datadrive(name)
82-
full_name = f"{rel_path}?{name}"
82+
full_name = f"{rel_path}?{quote(name)}"
8383
elif hasattr(item, "nodeid") and item.nodeid:
8484
full_name = normalize_testcase_name(item.nodeid)
85+
if "?" in full_name:
86+
path = full_name.split("?", 1)[0]
87+
case_name = full_name.split("?", 1)[-1]
88+
full_name = "?".join([path, quote(case_name)])
8589
else:
8690
rel_path, _, name = item.location
8791
name = name.replace(".", "/")
8892
name = decode_datadrive(name)
89-
full_name = f"{rel_path}?{name}"
93+
full_name = f"{rel_path}?{quote(name)}"
9094

9195
return full_name
9296

@@ -107,6 +111,7 @@ def decode_datadrive(name: str) -> str:
107111
https://docs.pytest.org/en/7.0.x/how-to/parametrize.html
108112
109113
test_include[\u4e2d\u6587-\u4e2d\u6587\u6c49\u5b57] -> test_include[中文-中文汉字]
114+
test_include[\U0001f604] -> test_include[😊]
110115
111116
用例名称中不允许出现[,因此如果有,一定是数据驱动的开头
112117
"""

‎pytest/tests/test_collector.py‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ def test_collect_testcases_when_selector_is_valid(self):
3737
self.assertEqual(len(re.LoadErrors), 2)
3838

3939
self.assertEqual(re.Tests[0].Name, "aa/bb/cc/test_in_sub_class.py?TestCompute/test_add")
40-
self.assertEqual(re.Tests[1].Name, "test_data_drive.py?test_eval/[2+4-6]")
41-
self.assertEqual(re.Tests[2].Name, "test_data_drive.py?test_eval/[3+5-8]")
42-
self.assertEqual(re.Tests[3].Name, "test_data_drive.py?test_eval/[6*9-42]")
40+
self.assertEqual(re.Tests[1].Name, "test_data_drive.py?test_eval/%5B2%2B4-6%5D")
41+
self.assertEqual(re.Tests[2].Name, "test_data_drive.py?test_eval/%5B3%2B5-8%5D")
42+
self.assertEqual(re.Tests[3].Name, "test_data_drive.py?test_eval/%5B6%2A9-42%5D")
4343
self.assertEqual(
4444
re.Tests[4].Name,
45-
"test_data_drive.py?test_special_data_drive_name/[中文-分号+[id:32]]",
45+
"test_data_drive.py?test_special_data_drive_name/%5B%E4%B8%AD%E6%96%87-%E5%88%86%E5%8F%B7%2B%5Bid%3A32%5D%5D",
4646
)
4747

4848
self.assertEqual(re.Tests[5].Name, "test_normal_case.py?test_success")
@@ -104,11 +104,17 @@ def test_collect_testcases_with_utf8_chars(self):
104104
self.assertEqual(len(re.Tests), 3)
105105
self.assertEqual(len(re.LoadErrors), 0)
106106

107-
self.assertEqual(re.Tests[0].Name, "test_data_drive_zh_cn.py?test_include/[#?-#?^$%!/]")
108-
self.assertEqual(re.Tests[1].Name, "test_data_drive_zh_cn.py?test_include/[中文-中文汉字]")
107+
self.assertEqual(
108+
re.Tests[0].Name,
109+
"test_data_drive_zh_cn.py?test_include/%5B%23%3F-%23%3F%5E%24%25%21/%5D",
110+
)
111+
self.assertEqual(
112+
re.Tests[1].Name,
113+
"test_data_drive_zh_cn.py?test_include/%5B%E4%B8%AD%E6%96%87-%E4%B8%AD%E6%96%87%E6%B1%89%E5%AD%97%5D",
114+
)
109115
self.assertEqual(
110116
re.Tests[2].Name,
111-
"test_data_drive_zh_cn.py?test_include/[파일을 찾을 수 없습니다-ファイルが見つかりません]",
117+
"test_data_drive_zh_cn.py?test_include/%5B%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EC%B0%BE%EC%9D%84%20%EC%88%98%20%EC%97%86%EC%8A%B5%EB%8B%88%EB%8B%A4-%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%8C%E8%A6%8B%E3%81%A4%E3%81%8B%E3%82%8A%E3%81%BE%E3%81%9B%E3%82%93%5D",
112118
)
113119

114120
def test_collect_testcases_with_case_drive_separator(self):
@@ -210,5 +216,6 @@ def test_collect_testcases_with_emoji(self):
210216
self.assertEqual(len(re.Tests), 1)
211217
self.assertEqual(len(re.LoadErrors), 0)
212218
self.assertEqual(
213-
re.Tests[0].Name, "test_emoji_data_drive.py?test_emoji_data_drive_name/[\U0001f604]"
219+
re.Tests[0].Name,
220+
"test_emoji_data_drive.py?test_emoji_data_drive_name/%5B%F0%9F%98%84%5D",
214221
)

‎pytest/tests/test_converter.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_pytest_path_cls_to_selector(self):
5252

5353
re = pytest_to_selector(mock, "/data/tests/")
5454

55-
self.assertEqual(re, "tests/test_data_drive_zh_cn.py?InnerClass/test_include/[2-8]")
55+
self.assertEqual(re, "tests/test_data_drive_zh_cn.py?InnerClass/test_include/%5B2-8%5D")
5656

5757
def test_pytest_node_id_to_selector_without_datadrive(self):
5858
mock = MagicMock()
@@ -74,7 +74,7 @@ def test_pytest_node_id_to_selector_with_datadrive(self):
7474

7575
self.assertEqual(
7676
re,
77-
"/data/tests/tests/test_data_drive_zh_cn.py?test_include/[#?-/[中文:203]]",
77+
"/data/tests/tests/test_data_drive_zh_cn.py?test_include/%5B%23%3F-/%5B%E4%B8%AD%E6%96%87%3A203%5D%5D",
7878
)
7979

8080
def test_pytest_location_to_selector(self):
@@ -86,7 +86,7 @@ def test_pytest_location_to_selector(self):
8686

8787
re = pytest_to_selector(mock, "/data/tests/")
8888

89-
self.assertEqual(re, "tests/test_data_drive_zh_cn.py?test_include/[AA-BB]")
89+
self.assertEqual(re, "tests/test_data_drive_zh_cn.py?test_include/%5BAA-BB%5D")
9090

9191

9292
class TestExtractCaseAndDataDrive:

‎pytest/tests/test_load.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_collect_testcases_from_args(self):
2424
self.assertEqual(len(re.Tests), 7)
2525
self.assertEqual(
2626
re.Tests[4].Name,
27-
"test_data_drive.py?test_special_data_drive_name/[中文-分号+[id:32]]",
27+
"test_data_drive.py?test_special_data_drive_name/%5B%E4%B8%AD%E6%96%87-%E5%88%86%E5%8F%B7%2B%5Bid%3A32%5D%5D",
2828
)
2929
self.assertEqual(
3030
re.Tests[6].Name,

‎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.37'
5+
version: '0.1.38'
66
langType: INTERPRETED
77
description: |-
88
pytest是一个成熟的全功能Python测试工具,可以帮助您编写更好的程序。此测试工具允许您在TestSolar上运行pytest。

‎pytest/uv.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)