Skip to content

Commit

Permalink
fix allure_full_name parsing when square bracers is in param contents (
Browse files Browse the repository at this point in the history
…fixes #622, via #708)
  • Loading branch information
skhomuti committed Nov 23, 2022
1 parent d01925f commit ed3a676
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 4 additions & 6 deletions allure-pytest/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ def allure_name(item, parameters):
return SafeFormatter().format(title, **{**parameters, **item.funcargs}) if title else name


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


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from hamcrest import assert_that
from hamcrest import assert_that, has_entry, ends_with
from allure_commons_test.report import has_test_case
from allure_commons_test.result import has_parameter, with_excluded, with_mode

Expand Down Expand Up @@ -173,3 +173,21 @@ def test_dynamic_parameter_override_from_fixture(executed_docstring_source):
has_parameter("param1", "'readable-value'")
)
)


def test_fullname_with_braces(executed_docstring_source):
"""
>>> import pytest
... import allure
>>> class TestClass:
... @pytest.mark.parametrize("param1", ["qwe]["])
... def test_with_braces(self, param1):
... pass
"""
assert_that(executed_docstring_source.allure_report,
has_test_case("test_with_braces[qwe][]",
has_entry('fullName', ends_with(".TestClass#test_with_braces")),
has_parameter("param1", "'qwe]['")
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


@allure.feature("Integration")
def test_pytest_docktest(allured_testdir):
def test_pytest_doctest(allured_testdir):
allured_testdir.testdir.makepyfile('''
def some_func():
"""
Expand All @@ -19,6 +19,6 @@ def some_func():
allured_testdir.run_with_allure("--doctest-modules")

assert_that(allured_testdir.allure_report,
has_test_case("test_pytest_docktest.some_func",
has_test_case("test_pytest_doctest.some_func",
with_status("passed"))
)

0 comments on commit ed3a676

Please sign in to comment.