Skip to content

Commit 97ee3c9

Browse files
Sup3rGeosseliverstov
authored andcommitted
bugfix and deprecated markinfo (fixes #291 fixes #119 via #295)
1 parent 90974e4 commit 97ee3c9

File tree

4 files changed

+43
-16
lines changed

4 files changed

+43
-16
lines changed

allure-pytest/src/listener.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ def pytest_runtest_teardown(self, item):
101101
test_result = self.allure_logger.get_test(uuid)
102102
test_result.labels.extend([Label(name=name, value=value) for name, value in allure_labels(item)])
103103
test_result.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)])
104-
test_result.labels.extend([Label(name=LabelType.TAG, value=value) for value in pytest_markers(item)])
105104
test_result.labels.extend([Label(name=name, value=value) for name, value in allure_suite_labels(item)])
106105
test_result.labels.append(Label(name=LabelType.HOST, value=self._host))
107106
test_result.labels.append(Label(name=LabelType.THREAD, value=self._thread))

allure-pytest/src/utils.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,27 @@ def allure_links(item):
6262

6363

6464
def pytest_markers(item):
65+
"""Do not consider pytest marks (has args/kwargs) as user tags
66+
e.g. @pytest.mark.parametrize/skip/skipif/usefixtures etc..."""
6567
for keyword in item.keywords.keys():
66-
if not any((keyword.startswith('allure_'),
67-
keyword == 'parametrize')):
68-
marker = item.get_marker(keyword)
69-
if marker:
70-
yield mark_to_str(marker)
68+
if keyword.startswith('allure_'):
69+
continue
70+
marker = item.get_closest_marker(keyword)
71+
if marker is None:
72+
continue
73+
user_tag_mark = (not marker.args and not marker.kwargs)
74+
if marker.name == "marker" or user_tag_mark:
75+
yield mark_to_str(marker)
7176

7277

7378
def mark_to_str(marker):
7479
args = [represent(arg) for arg in marker.args]
7580
kwargs = ['{name}={value}'.format(name=key, value=represent(marker.kwargs[key])) for key in marker.kwargs]
81+
markstr = '{name}'.format(name=marker.name)
7682
if args or kwargs:
7783
parameters = ', '.join(args + kwargs)
78-
return '@pytest.mark.{name}({parameters})'.format(name=marker.name, parameters=parameters)
79-
else:
80-
return '@pytest.mark.{name}'.format(name=marker.name)
84+
markstr = '{}({})'.format(markstr, parameters)
85+
return markstr
8186

8287

8388
def allure_package(item):

allure-pytest/test/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def allure_report(request, tmpdir_factory):
7373
module = request.module.__file__
7474
tmpdir = tmpdir_factory.mktemp('data')
7575
_runner(tmpdir.strpath, module)
76+
with open("debug-runner", "a") as debugfile:
77+
print(tmpdir.strpath, file=debugfile)
7678
return AllureReport(tmpdir.strpath)
7779

7880

allure-pytest/test/labels/mark/function_marker_test.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,29 @@ def test_pytest_marker():
1818
>>> allure_report = getfixture('allure_report')
1919
>>> assert_that(allure_report,
2020
... has_test_case('test_pytest_marker',
21-
... has_tag('@pytest.mark.cool'),
22-
... has_tag('@pytest.mark.stuff')
21+
... has_tag('cool'),
22+
... has_tag('stuff')
23+
... )
24+
... )
25+
"""
26+
pass
27+
28+
29+
@pytest.mark.usermark1
30+
@pytest.mark.usermark2
31+
@pytest.mark.parametrize("param", ["foo"])
32+
@pytest.mark.skipif(False, reason="reason2")
33+
@pytest.mark.skipif(False, reason="reason1")
34+
def test_omit_pytest_markers(param):
35+
"""
36+
>>> allure_report = getfixture('allure_report')
37+
>>> assert_that(allure_report,
38+
... has_test_case('test_omit_pytest_markers[foo]',
39+
... has_tag("usermark1"),
40+
... has_tag("usermark2"),
41+
... is_not(has_tag("skipif(False, reason='reason2')")),
42+
... is_not(has_tag("skipif(False, reason='reason1')")),
43+
... is_not(has_tag("parametrize('param', ['foo'])")),
2344
... )
2445
... )
2546
"""
@@ -32,7 +53,7 @@ def test_pytest_marker_with_args():
3253
>>> allure_report = getfixture('allure_report')
3354
>>> assert_that(allure_report,
3455
... has_test_case('test_pytest_marker_with_args',
35-
... has_tag("@pytest.mark.marker('cool', 'stuff')")
56+
... has_tag("marker('cool', 'stuff')")
3657
... )
3758
... )
3859
"""
@@ -45,7 +66,7 @@ def test_pytest_marker_with_kwargs():
4566
>>> allure_report = getfixture('allure_report')
4667
>>> assert_that(allure_report,
4768
... has_test_case('test_pytest_marker_with_kwargs',
48-
... has_tag("@pytest.mark.marker(stuff='cool')")
69+
... has_tag("marker(stuff='cool')")
4970
... )
5071
... )
5172
"""
@@ -59,7 +80,7 @@ def test_pytest_marker_with_kwargs_native_encoding():
5980
>>> allure_report = getfixture('allure_report')
6081
>>> assert_that(allure_report,
6182
... has_test_case('test_pytest_marker_with_kwargs_native_encoding',
62-
... has_tag("@pytest.mark.marker(stuff=%s)" % represent('я'))
83+
... has_tag("marker(stuff=%s)" % represent('я'))
6384
... )
6485
... )
6586
"""
@@ -73,7 +94,7 @@ def test_pytest_marker_with_kwargs_utf_encoding():
7394
>>> allure_report = getfixture('allure_report')
7495
>>> assert_that(allure_report,
7596
... has_test_case('test_pytest_marker_with_kwargs_utf_encoding',
76-
... has_tag("@pytest.mark.marker(stuff=%s)" % represent('я'))
97+
... has_tag("marker(stuff=%s)" % represent('я'))
7798
... )
7899
... )
79100
"""
@@ -86,7 +107,7 @@ def test_pytest_marker_with_args_and_kwargs():
86107
>>> allure_report = getfixture('allure_report')
87108
>>> assert_that(allure_report,
88109
... has_test_case('test_pytest_marker_with_args_and_kwargs',
89-
... has_tag("@pytest.mark.marker('that', stuff='cool')")
110+
... has_tag("marker('that', stuff='cool')")
90111
... )
91112
... )
92113
"""

0 commit comments

Comments
 (0)