Skip to content

Fix allure_full_name parsing when square bracers is in param contents #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
)