Skip to content

show pytest.mark markers with args and kwargs in report tags section … #492

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
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
14 changes: 7 additions & 7 deletions allure-pytest/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,23 @@ def allure_links(item):


def pytest_markers(item):
"""Do not consider pytest marks (has args/kwargs) as user tags
e.g. @pytest.mark.parametrize/skip/skipif/usefixtures etc..."""
for keyword in item.keywords.keys():
if keyword.startswith('allure_'):
if any([keyword.startswith('allure_'), keyword == 'parametrize']):
continue
marker = item.get_closest_marker(keyword)
if marker is None:
continue
user_tag_mark = (not marker.args and not marker.kwargs)
if marker.name == "marker" or user_tag_mark:
yield mark_to_str(marker)

yield mark_to_str(marker)


def mark_to_str(marker):
args = [represent(arg) for arg in marker.args]
kwargs = ['{name}={value}'.format(name=key, value=represent(marker.kwargs[key])) for key in marker.kwargs]
markstr = '{name}'.format(name=marker.name)
if marker.name in ('filterwarnings', 'skip', 'skipif', 'xfail', 'usefixtures', 'tryfirst', 'trylast'):
markstr = '@pytest.mark.{name}'.format(name=marker.name)
else:
markstr = '{name}'.format(name=marker.name)
if args or kwargs:
parameters = ', '.join(args + kwargs)
markstr = '{}({})'.format(markstr, parameters)
Expand Down
28 changes: 22 additions & 6 deletions allure-pytest/test/acceptance/label/tag/tag_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_pytest_marker(executed_docstring_source):
)


def test_omit_pytest_markers(executed_docstring_source):
def test_show_reserved_pytest_markers_full_decorator(executed_docstring_source):
"""
>>> import pytest

Expand All @@ -33,17 +33,33 @@ def test_omit_pytest_markers(executed_docstring_source):
... @pytest.mark.parametrize("param", ["foo"])
... @pytest.mark.skipif(False, reason="reason2")
... @pytest.mark.skipif(False, reason="reason1")
... def test_omit_pytest_markers_example(param):
... def test_show_reserved_pytest_markers_full_decorator_example(param):
... pass
"""

assert_that(executed_docstring_source.allure_report,
has_test_case('test_omit_pytest_markers_example[foo]',
has_test_case('test_show_reserved_pytest_markers_full_decorator_example[foo]',
has_tag("usermark1"),
has_tag("usermark2"),
not_(has_tag("skipif(False, reason='reason2')")),
not_(has_tag("skipif(False, reason='reason1')")),
not_(has_tag("parametrize('param', ['foo'])"))
has_tag("@pytest.mark.skipif(False, reason='reason1')"),
not_(has_tag("@pytest.mark.skipif(False, reason='reason2')")),
not_(has_tag("@pytest.mark.parametrize('param', ['foo'])"))
)
)


def test_pytest_xfail_marker(executed_docstring_source):
"""
>>> import pytest

>>> @pytest.mark.xfail(reason='this is unexpect pass')
... def test_pytest_xfail_marker_example():
... pass
"""

assert_that(executed_docstring_source.allure_report,
has_test_case('test_pytest_xfail_marker_example',
has_tag("@pytest.mark.xfail(reason='this is unexpect pass')"),
)
)

Expand Down