From 5e3b4b051c0390d32aa9ae455815f9e3509c2c90 Mon Sep 17 00:00:00 2001 From: ornichola <1502708+ornichola@users.noreply.github.com> Date: Tue, 26 May 2020 04:24:05 +0300 Subject: [PATCH] show pytest.mark markers with args and kwargs in report tags section (fixes #488) --- allure-pytest/src/utils.py | 14 +++++----- .../test/acceptance/label/tag/tag_test.py | 28 +++++++++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/allure-pytest/src/utils.py b/allure-pytest/src/utils.py index 5dc78160..5153b6e1 100644 --- a/allure-pytest/src/utils.py +++ b/allure-pytest/src/utils.py @@ -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) diff --git a/allure-pytest/test/acceptance/label/tag/tag_test.py b/allure-pytest/test/acceptance/label/tag/tag_test.py index 0a3ca446..e029d2b1 100644 --- a/allure-pytest/test/acceptance/label/tag/tag_test.py +++ b/allure-pytest/test/acceptance/label/tag/tag_test.py @@ -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 @@ -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')"), ) )