GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Don't convert built-in (reserved) pytest markers to allure tags (fix #817) by sharovd · Pull Request #862 · allure-framework/allure-python

Don't convert built-in (reserved) pytest markers to allure tags (fix #817) #862

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.

Sign up for GitHub

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
delatrie merged 3 commits into allure-framework:master from sharovd:fix-817-ignore-built-in-marks
Jun 9, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

Don't convert built-in (reserved) pytest markers to allure tags (fix #817) #862

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
3 commits
Select commit Hold shift + click to select a range
e141153
fix: don't convert built-in (reserved) pytest markers to allure tags …
sharovd May 17, 2025
26b6a9c
fix the issue found by the linter (F401 'allure_commons.utils.represe…
sharovd May 17, 2025
c3b3197
apply suggestions from code review
sharovd Jun 9, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

36 changes: 16 additions & 20 deletions 36 allure-pytest/src/utils.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from itertools import chain, islice
from allure_commons.utils import represent, SafeFormatter, md5
from allure_commons.utils import SafeFormatter, md5
from allure_commons.utils import format_exception, format_traceback
from allure_commons.model2 import Status
from allure_commons.model2 import StatusDetails
Expand All @@ -20,6 +20,15 @@
LabelType.SUB_SUITE
]

MARK_NAMES_TO_IGNORE = {
"usefixtures",
"filterwarnings",
"skip",
"skipif",
"xfail",
"parametrize",
}


def get_marker_value(item, keyword):
marker = item.get_closest_marker(keyword)
Expand Down Expand Up @@ -81,27 +90,14 @@ def format_allure_link(config, url, link_type):


def pytest_markers(item):
for keyword in item.keywords.keys():
if any([keyword.startswith('allure_'), keyword == 'parametrize']):
continue
marker = item.get_closest_marker(keyword)
if marker is None:
continue

yield mark_to_str(marker)
for mark in item.iter_markers():
if should_convert_mark_to_tag(mark):
yield mark.name


def mark_to_str(marker):
args = [represent(arg) for arg in marker.args]
kwargs = [f'{key}={represent(value)}' for key, value in marker.kwargs.items()]
if marker.name in ('filterwarnings', 'skip', 'skipif', 'xfail', 'usefixtures', 'tryfirst', 'trylast'):
markstr = f'@pytest.mark.{marker.name}'
else:
markstr = str(marker.name)
if args or kwargs:
parameters = ', '.join(args + kwargs)
markstr = f'{markstr}({parameters})'
return markstr
def should_convert_mark_to_tag(mark):
return mark.name not in MARK_NAMES_TO_IGNORE and \
not mark.args and not mark.kwargs


def allure_package(item):
Expand Down
148 changes: 102 additions & 46 deletions 148 tests/allure_pytest/acceptance/label/tag/tag_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from hamcrest import assert_that, not_
from hamcrest import assert_that, not_, anything
from tests.allure_pytest.pytest_runner import AllurePytestRunner

from allure_commons_test.report import has_test_case
from allure_commons_test.label import has_tag


def test_pytest_marker(allure_pytest_runner: AllurePytestRunner):
def test_pytest_simple_markers_are_converted_to_allure_tags(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.cool
... @pytest.mark.stuff
... def test_pytest_marker_example():
... def test_pytest_simple_markers_are_converted_to_allure_tags_example():
... pass
"""

Expand All @@ -20,25 +22,21 @@ def test_pytest_marker(allure_pytest_runner: AllurePytestRunner):
assert_that(
allure_results,
has_test_case(
"test_pytest_marker_example",
"test_pytest_simple_markers_are_converted_to_allure_tags_example",
has_tag("cool"),
has_tag("stuff")
)
)


def test_show_reserved_pytest_markers_full_decorator(
allure_pytest_runner: AllurePytestRunner
def test_pytest_marker_with_args_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @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_show_reserved_pytest_markers_full_decorator_example(param):
>>> @pytest.mark.marker('cool', 'stuff')
... def test_pytest_marker_with_args_is_not_converted_to_allure_tag_example():
... pass
"""

Expand All @@ -47,26 +45,46 @@ def test_show_reserved_pytest_markers_full_decorator(
assert_that(
allure_results,
has_test_case(
"test_show_reserved_pytest_markers_full_decorator_example[foo]",
has_tag("usermark1"),
has_tag("usermark2"),
has_tag("@pytest.mark.skipif(False, reason='reason1')"),
"test_pytest_marker_with_args_is_not_converted_to_allure_tag_example",
not_(
has_tag("@pytest.mark.skipif(False, reason='reason2')")
),
has_tag(anything())
)
)
)


def test_pytest_marker_with_kwargs_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.marker(stuff='cool')
... def test_pytest_marker_with_kwargs_is_not_converted_to_allure_tag_example():
... pass
"""

allure_results = allure_pytest_runner.run_docstring()

assert_that(
allure_results,
has_test_case(
"test_pytest_marker_with_kwargs_is_not_converted_to_allure_tag_example",
not_(
has_tag("@pytest.mark.parametrize('param', ['foo'])")
has_tag(anything())
)
)
)


def test_pytest_xfail_marker(allure_pytest_runner: AllurePytestRunner):
def test_pytest_reserved_marker_usefixtures_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

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

Expand All @@ -75,18 +93,22 @@ def test_pytest_xfail_marker(allure_pytest_runner: AllurePytestRunner):
assert_that(
allure_results,
has_test_case(
"test_pytest_xfail_marker_example",
has_tag("@pytest.mark.xfail(reason='this is unexpect pass')")
"test_pytest_reserved_marker_usefixtures_is_not_converted_to_allure_tag_example",
not_(
has_tag(anything())
)
)
)


def test_pytest_marker_with_args(allure_pytest_runner: AllurePytestRunner):
def test_pytest_reserved_marker_filterwarnings_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.marker('cool', 'stuff')
... def test_pytest_marker_with_args_example():
>>> @pytest.mark.filterwarnings('ignore:val')
... def test_pytest_reserved_marker_filterwarnings_is_not_converted_to_allure_tag_example():
... pass
"""

Expand All @@ -95,18 +117,22 @@ def test_pytest_marker_with_args(allure_pytest_runner: AllurePytestRunner):
assert_that(
allure_results,
has_test_case(
"test_pytest_marker_with_args_example",
has_tag("marker('cool', 'stuff')")
"test_pytest_reserved_marker_filterwarnings_is_not_converted_to_allure_tag_example",
not_(
has_tag(anything())
)
)
)


def test_pytest_marker_with_kwargs(allure_pytest_runner: AllurePytestRunner):
def test_pytest_reserved_marker_skip_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.marker(stuff='cool')
... def test_pytest_marker_with_kwargs_example():
>>> @pytest.mark.skip(reason='reason')
... def test_pytest_reserved_marker_skip_is_not_converted_to_allure_tag_example():
... pass
"""

Expand All @@ -115,20 +141,22 @@ def test_pytest_marker_with_kwargs(allure_pytest_runner: AllurePytestRunner):
assert_that(
allure_results,
has_test_case(
"test_pytest_marker_with_kwargs_example",
has_tag("marker(stuff='cool')")
"test_pytest_reserved_marker_skip_is_not_converted_to_allure_tag_example",
not_(
has_tag(anything())
)
)
)


def test_pytest_marker_with_kwargs_native_encoding(
allure_pytest_runner: AllurePytestRunner
def test_pytest_reserved_marker_skipif_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.marker(stuff='я')
... def test_pytest_marker_with_kwargs_native_encoding_example():
>>> @pytest.mark.skipif(False, reason='reason')
... def test_pytest_reserved_marker_skipif_is_not_converted_to_allure_tag_example():
... pass
"""

Expand All @@ -137,20 +165,22 @@ def test_pytest_marker_with_kwargs_native_encoding(
assert_that(
allure_results,
has_test_case(
"test_pytest_marker_with_kwargs_native_encoding_example",
has_tag("marker(stuff='я')")
"test_pytest_reserved_marker_skipif_is_not_converted_to_allure_tag_example",
not_(
has_tag(anything())
)
)
)


def test_pytest_marker_with_kwargs_utf_encoding(
allure_pytest_runner: AllurePytestRunner
def test_pytest_reserved_marker_xfail_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.marker(stuff='я')
... def test_pytest_marker_with_kwargs_utf_encoding_example():
>>> @pytest.mark.xfail(reason='this is unexpect pass')
... def test_pytest_reserved_marker_xfail_is_not_converted_to_allure_tag_example():
... pass
"""

Expand All @@ -159,7 +189,33 @@ def test_pytest_marker_with_kwargs_utf_encoding(
assert_that(
allure_results,
has_test_case(
"test_pytest_marker_with_kwargs_utf_encoding_example",
has_tag("marker(stuff='я')")
"test_pytest_reserved_marker_xfail_is_not_converted_to_allure_tag_example",
not_(
has_tag(anything())
)
)
)


def test_pytest_reserved_marker_parametrize_is_not_converted_to_allure_tag(
allure_pytest_runner: AllurePytestRunner
):
"""
>>> import pytest

>>> @pytest.mark.parametrize("param", ["foo"])
... def test_pytest_reserved_marker_parametrize_is_not_converted_to_allure_tag_example(param):
... pass
"""

allure_results = allure_pytest_runner.run_docstring()

assert_that(
allure_results,
has_test_case(
"test_pytest_reserved_marker_parametrize_is_not_converted_to_allure_tag_example[foo]",
not_(
has_tag(anything())
)
)
)
4 changes: 2 additions & 2 deletions 4 tests/allure_pytest/externals/pytest_rerunfailures/pytest_rerunfailures_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ def __count_labels(tc, name):

assert len(output.test_cases) == 2
assert __count_labels(output.test_cases[0], "suite") == 1
assert __count_labels(output.test_cases[0], "tag") == 1
assert __count_labels(output.test_cases[0], "tag") == 0
assert __count_labels(output.test_cases[1], "suite") == 1
assert __count_labels(output.test_cases[1], "tag") == 1
assert __count_labels(output.test_cases[1], "tag") == 0
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.