Skip to content
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
1 change: 0 additions & 1 deletion allure-pytest/src/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 13 additions & 8 deletions allure-pytest/src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 2 additions & 0 deletions allure-pytest/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
35 changes: 28 additions & 7 deletions allure-pytest/test/labels/mark/function_marker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])")),
... )
... )
"""
Expand All @@ -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')")
... )
... )
"""
Expand All @@ -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')")
... )
... )
"""
Expand All @@ -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('я'))
... )
... )
"""
Expand All @@ -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('я'))
... )
... )
"""
Expand All @@ -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')")
... )
... )
"""
Expand Down