Skip to content

Commit fed50ce

Browse files
authored
show pytest.mark markers with args and kwargs in report tags section (fixes #488 via #492)
1 parent 338262c commit fed50ce

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

allure-pytest/src/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,23 @@ def allure_links(item):
7777

7878

7979
def pytest_markers(item):
80-
"""Do not consider pytest marks (has args/kwargs) as user tags
81-
e.g. @pytest.mark.parametrize/skip/skipif/usefixtures etc..."""
8280
for keyword in item.keywords.keys():
83-
if keyword.startswith('allure_'):
81+
if any([keyword.startswith('allure_'), keyword == 'parametrize']):
8482
continue
8583
marker = item.get_closest_marker(keyword)
8684
if marker is None:
8785
continue
88-
user_tag_mark = (not marker.args and not marker.kwargs)
89-
if marker.name == "marker" or user_tag_mark:
90-
yield mark_to_str(marker)
86+
87+
yield mark_to_str(marker)
9188

9289

9390
def mark_to_str(marker):
9491
args = [represent(arg) for arg in marker.args]
9592
kwargs = ['{name}={value}'.format(name=key, value=represent(marker.kwargs[key])) for key in marker.kwargs]
96-
markstr = '{name}'.format(name=marker.name)
93+
if marker.name in ('filterwarnings', 'skip', 'skipif', 'xfail', 'usefixtures', 'tryfirst', 'trylast'):
94+
markstr = '@pytest.mark.{name}'.format(name=marker.name)
95+
else:
96+
markstr = '{name}'.format(name=marker.name)
9797
if args or kwargs:
9898
parameters = ', '.join(args + kwargs)
9999
markstr = '{}({})'.format(markstr, parameters)

allure-pytest/test/acceptance/label/tag/tag_test.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_pytest_marker(executed_docstring_source):
2424
)
2525

2626

27-
def test_omit_pytest_markers(executed_docstring_source):
27+
def test_show_reserved_pytest_markers_full_decorator(executed_docstring_source):
2828
"""
2929
>>> import pytest
3030
@@ -33,17 +33,33 @@ def test_omit_pytest_markers(executed_docstring_source):
3333
... @pytest.mark.parametrize("param", ["foo"])
3434
... @pytest.mark.skipif(False, reason="reason2")
3535
... @pytest.mark.skipif(False, reason="reason1")
36-
... def test_omit_pytest_markers_example(param):
36+
... def test_show_reserved_pytest_markers_full_decorator_example(param):
3737
... pass
3838
"""
3939

4040
assert_that(executed_docstring_source.allure_report,
41-
has_test_case('test_omit_pytest_markers_example[foo]',
41+
has_test_case('test_show_reserved_pytest_markers_full_decorator_example[foo]',
4242
has_tag("usermark1"),
4343
has_tag("usermark2"),
44-
not_(has_tag("skipif(False, reason='reason2')")),
45-
not_(has_tag("skipif(False, reason='reason1')")),
46-
not_(has_tag("parametrize('param', ['foo'])"))
44+
has_tag("@pytest.mark.skipif(False, reason='reason1')"),
45+
not_(has_tag("@pytest.mark.skipif(False, reason='reason2')")),
46+
not_(has_tag("@pytest.mark.parametrize('param', ['foo'])"))
47+
)
48+
)
49+
50+
51+
def test_pytest_xfail_marker(executed_docstring_source):
52+
"""
53+
>>> import pytest
54+
55+
>>> @pytest.mark.xfail(reason='this is unexpect pass')
56+
... def test_pytest_xfail_marker_example():
57+
... pass
58+
"""
59+
60+
assert_that(executed_docstring_source.allure_report,
61+
has_test_case('test_pytest_xfail_marker_example',
62+
has_tag("@pytest.mark.xfail(reason='this is unexpect pass')"),
4763
)
4864
)
4965

0 commit comments

Comments
 (0)