Skip to content

Commit ee4e58c

Browse files
committed
fix(pytest): preserve double colons in file paths
1 parent 04e5f70 commit ee4e58c

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎allure-pytest/src/utils.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@
3232

3333
class ParsedPytestNodeId:
3434
def __init__(self, item: pytest.Item):
35-
filepath = item.nodeid.split("::", 1)[0]
35+
filepath = next(
36+
(
37+
node.nodeid
38+
for node in reversed(item.listchain())
39+
if isinstance(node, pytest.File)
40+
),
41+
item.nodeid.split("::", 1)[0],
42+
)
3643
self.filepath = filepath
3744
self.path_segments = filepath.split("/")
3845
*parent_dirs, filename = ensure_len(self.path_segments, 1)

‎tests/allure_pytest/acceptance/titlepath/titlepath_test.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
from hamcrest import assert_that
33
from tests.allure_pytest.pytest_runner import AllurePytestRunner
44

5+
from allure_commons_test.label import has_package
6+
from allure_commons_test.label import has_suite
57
from allure_commons_test.report import has_test_case
8+
from allure_commons_test.result import has_full_name
69
from allure_commons_test.result import has_title_path
710

811

@@ -73,3 +76,27 @@ def test_nested_class_method_title_path(allure_pytest_runner: AllurePytestRunner
7376
has_title_path(*path_segments, "TestBar", "TestBaz"),
7477
)
7578
)
79+
80+
81+
def test_file_path_with_double_colon(
82+
allure_pytest_runner: AllurePytestRunner,
83+
):
84+
allure_pytest_runner.pytester.makepyfile(**{
85+
"test_module::part.py": """
86+
def test_fn():
87+
pass
88+
"""
89+
})
90+
91+
allure_results = allure_pytest_runner.run_pytest()
92+
93+
assert_that(
94+
allure_results,
95+
has_test_case(
96+
"test_fn",
97+
has_full_name("test_module::part#test_fn"),
98+
has_title_path("test_module::part.py"),
99+
has_package("test_module::part"),
100+
has_suite("test_module::part"),
101+
)
102+
)

0 commit comments

Comments
 (0)