diff --git a/allure-pytest/src/listener.py b/allure-pytest/src/listener.py index 55e444a7..894b57a2 100644 --- a/allure-pytest/src/listener.py +++ b/allure-pytest/src/listener.py @@ -101,7 +101,6 @@ def pytest_runtest_teardown(self, item): test_result = self.allure_logger.get_test(uuid) test_result.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)]) test_result.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)]) - test_result.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)]) test_result.labels.extend([Label(name=name, value=value) for name, value in allure_suite_labels(item)]) test_result.labels.append(Label(name=LabelType.HOST, value=self._host)) test_result.labels.append(Label(name=LabelType.THREAD, value=self._thread)) diff --git a/allure-pytest/src/utils.py b/allure-pytest/src/utils.py index bf23779e..d2ee92f0 100644 --- a/allure-pytest/src/utils.py +++ b/allure-pytest/src/utils.py @@ -62,22 +62,27 @@ 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 not any((keyword.startswith('allure_'), - keyword == 'parametrize')): - marker = item.get_marker(keyword) - if marker: - yield mark_to_str(marker) + if keyword.startswith('allure_'): + 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) 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 args or kwargs: parameters = ', '.join(args + kwargs) - return '@pytest.mark.{name}({parameters})'.format(name=marker.name, parameters=parameters) - else: - return '@pytest.mark.{name}'.format(name=marker.name) + markstr = '{}({})'.format(markstr, parameters) + return markstr def allure_package(item): diff --git a/allure-pytest/test/conftest.py b/allure-pytest/test/conftest.py index 96c9b48b..8d0132c4 100644 --- a/allure-pytest/test/conftest.py +++ b/allure-pytest/test/conftest.py @@ -73,6 +73,8 @@ def allure_report(request, tmpdir_factory): module = request.module.__file__ tmpdir = tmpdir_factory.mktemp('data') _runner(tmpdir.strpath, module) + with open("debug-runner", "a") as debugfile: + print(tmpdir.strpath, file=debugfile) return AllureReport(tmpdir.strpath) diff --git a/allure-pytest/test/labels/mark/function_marker_test.py b/allure-pytest/test/labels/mark/function_marker_test.py index f1a1a636..1e525909 100644 --- a/allure-pytest/test/labels/mark/function_marker_test.py +++ b/allure-pytest/test/labels/mark/function_marker_test.py @@ -18,8 +18,29 @@ def test_pytest_marker(): >>> allure_report = getfixture('allure_report') >>> assert_that(allure_report, ... has_test_case('test_pytest_marker', - ... has_tag('@pytest.mark.cool'), - ... has_tag('@pytest.mark.stuff') + ... has_tag('cool'), + ... has_tag('stuff') + ... ) + ... ) + """ + pass + + +@pytest.mark.usermark1 +@pytest.mark.usermark2 +@pytest.mark.parametrize("param", ["foo"]) +@pytest.mark.skipif(False, reason="reason2") +@pytest.mark.skipif(False, reason="reason1") +def test_omit_pytest_markers(param): + """ + >>> allure_report = getfixture('allure_report') + >>> assert_that(allure_report, + ... has_test_case('test_omit_pytest_markers[foo]', + ... has_tag("usermark1"), + ... has_tag("usermark2"), + ... is_not(has_tag("skipif(False, reason='reason2')")), + ... is_not(has_tag("skipif(False, reason='reason1')")), + ... is_not(has_tag("parametrize('param', ['foo'])")), ... ) ... ) """ @@ -32,7 +53,7 @@ def test_pytest_marker_with_args(): >>> allure_report = getfixture('allure_report') >>> assert_that(allure_report, ... has_test_case('test_pytest_marker_with_args', - ... has_tag("@pytest.mark.marker('cool', 'stuff')") + ... has_tag("marker('cool', 'stuff')") ... ) ... ) """ @@ -45,7 +66,7 @@ def test_pytest_marker_with_kwargs(): >>> allure_report = getfixture('allure_report') >>> assert_that(allure_report, ... has_test_case('test_pytest_marker_with_kwargs', - ... has_tag("@pytest.mark.marker(stuff='cool')") + ... has_tag("marker(stuff='cool')") ... ) ... ) """ @@ -59,7 +80,7 @@ def test_pytest_marker_with_kwargs_native_encoding(): >>> allure_report = getfixture('allure_report') >>> assert_that(allure_report, ... has_test_case('test_pytest_marker_with_kwargs_native_encoding', - ... has_tag("@pytest.mark.marker(stuff=%s)" % represent('я')) + ... has_tag("marker(stuff=%s)" % represent('я')) ... ) ... ) """ @@ -73,7 +94,7 @@ def test_pytest_marker_with_kwargs_utf_encoding(): >>> allure_report = getfixture('allure_report') >>> assert_that(allure_report, ... has_test_case('test_pytest_marker_with_kwargs_utf_encoding', - ... has_tag("@pytest.mark.marker(stuff=%s)" % represent('я')) + ... has_tag("marker(stuff=%s)" % represent('я')) ... ) ... ) """ @@ -86,7 +107,7 @@ def test_pytest_marker_with_args_and_kwargs(): >>> allure_report = getfixture('allure_report') >>> assert_that(allure_report, ... has_test_case('test_pytest_marker_with_args_and_kwargs', - ... has_tag("@pytest.mark.marker('that', stuff='cool')") + ... has_tag("marker('that', stuff='cool')") ... ) ... ) """