Skip to content

Commit e5e6bf2

Browse files
committed
兼容windows平台执行
1 parent 2ae85a0 commit e5e6bf2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎pytest/src/testsolar_pytestx/converter.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def pytest_to_selector(item: Item, project_path: str) -> str:
7878

7979
if hasattr(item, "path") and hasattr(item, "cls") and item.path:
8080
rel_path = os.path.relpath(item.path, project_path)
81+
# 统一使用正斜杠,确保跨平台一致性
82+
rel_path = rel_path.replace(os.sep, "/")
8183
name = item.name
8284
if item.cls:
8385
name = item.cls.__name__ + "/" + name
@@ -87,6 +89,8 @@ def pytest_to_selector(item: Item, project_path: str) -> str:
8789
full_name = normalize_testcase_name(item.nodeid)
8890
else:
8991
rel_path, _, name = item.location
92+
# 统一使用正斜杠,确保跨平台一致性
93+
rel_path = rel_path.replace(os.sep, "/")
9094
name = name.replace(".", "/")
9195
name = decode_datadrive(name)
9296
full_name = f"{rel_path}?{name}"
@@ -140,6 +144,8 @@ def normalize_testcase_name(name: str, sub_case_key: Optional[str] = None) -> st
140144
-> test_directory/test_module.py?TestExampleClass/test_example_function/[datedrive]
141145
"""
142146
assert "::" in name
147+
# 统一使用正斜杠,确保跨平台一致性
148+
name = name.replace(os.sep, "/")
143149
name = name.replace("::", "?", 1).replace( # 第一个分割符是文件,因此替换为?
144150
"::", "/"
145151
) # 后续的分割符是测试用例名称,替换为/

0 commit comments

Comments
 (0)