Skip to content

Commit ed3a676

Browse files
authored
fix allure_full_name parsing when square bracers is in param contents (fixes #622, via #708)
1 parent d01925f commit ed3a676

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

allure-pytest/src/utils.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,11 @@ def allure_name(item, parameters):
114114
return SafeFormatter().format(title, **{**parameters, **item.funcargs}) if title else name
115115

116116

117-
def allure_full_name(item):
118-
parts = item.nodeid.split('::')
117+
def allure_full_name(item: pytest.Item):
119118
package = allure_package(item)
120-
clazz = '.{clazz}'.format(clazz=parts[1]) if len(parts) > 2 else ''
121-
test_with_params = parts[-1]
122-
test = test_with_params.rsplit("[", 1)[0]
123-
full_name = '{package}{clazz}#{test}'.format(package=package, clazz=clazz, test=test)
119+
class_name = f".{item.parent.name}" if isinstance(item.parent, pytest.Class) else ''
120+
test = item.originalname if isinstance(item, pytest.Function) else item.name.split("[")[0]
121+
full_name = f'{package}{class_name}#{test}'
124122
return escape_name(full_name)
125123

126124

allure-pytest/test/acceptance/parametrization/parametrization_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from hamcrest import assert_that
2+
from hamcrest import assert_that, has_entry, ends_with
33
from allure_commons_test.report import has_test_case
44
from allure_commons_test.result import has_parameter, with_excluded, with_mode
55

@@ -173,3 +173,21 @@ def test_dynamic_parameter_override_from_fixture(executed_docstring_source):
173173
has_parameter("param1", "'readable-value'")
174174
)
175175
)
176+
177+
178+
def test_fullname_with_braces(executed_docstring_source):
179+
"""
180+
>>> import pytest
181+
... import allure
182+
183+
>>> class TestClass:
184+
... @pytest.mark.parametrize("param1", ["qwe]["])
185+
... def test_with_braces(self, param1):
186+
... pass
187+
"""
188+
assert_that(executed_docstring_source.allure_report,
189+
has_test_case("test_with_braces[qwe][]",
190+
has_entry('fullName', ends_with(".TestClass#test_with_braces")),
191+
has_parameter("param1", "'qwe]['")
192+
)
193+
)

allure-pytest/test/integration/pytest_doctest/pytest_doctest_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
@allure.feature("Integration")
8-
def test_pytest_docktest(allured_testdir):
8+
def test_pytest_doctest(allured_testdir):
99
allured_testdir.testdir.makepyfile('''
1010
def some_func():
1111
"""
@@ -19,6 +19,6 @@ def some_func():
1919
allured_testdir.run_with_allure("--doctest-modules")
2020

2121
assert_that(allured_testdir.allure_report,
22-
has_test_case("test_pytest_docktest.some_func",
22+
has_test_case("test_pytest_doctest.some_func",
2323
with_status("passed"))
2424
)

0 commit comments

Comments
 (0)