Skip to content

Commit bd8b85a

Browse files
authored
Update item tags through the attributes
2 parents e4907c1 + 4f9ff56 commit bd8b85a

File tree

6 files changed

+43
-73
lines changed

6 files changed

+43
-73
lines changed

pytest_reportportal/listener.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,7 @@ def __init__(self, py_test_service,
3232

3333
@pytest.hookimpl(hookwrapper=True)
3434
def pytest_runtest_protocol(self, item):
35-
# Adding issues id marks to the test item
36-
# if client doesn't support item updates
37-
update_supported = self.PyTestService.is_item_update_supported()
38-
if not update_supported:
39-
self._add_issue_id_marks(item)
40-
35+
self._add_issue_id_marks(item)
4136
item_id = self.PyTestService.start_pytest_item(item)
4237
if PYTEST_HAS_LOGGING_PLUGIN:
4338
# This check can go away once we support pytest >= 3.3
@@ -47,11 +42,6 @@ def pytest_runtest_protocol(self, item):
4742
yield
4843
else:
4944
yield
50-
# Updating item in RP (tags and description)
51-
# if client supports
52-
if update_supported:
53-
self._add_issue_id_marks(item)
54-
self.PyTestService.update_pytest_item(item)
5545
# Finishing item in RP
5646
self.PyTestService.finish_pytest_item(
5747
item, item_id, self.result or 'SKIPPED', self.issue or None)

pytest_reportportal/service.py

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def start_pytest_item(self, test_item=None):
245245
self._hier_parts[part]["item_id"] = item_id
246246

247247
start_rq = {
248+
'attributes': self._get_item_markers(test_item),
248249
'name': self._get_item_name(test_item),
249250
'description': self._get_item_description(test_item),
250251
'start_time': timestamp(),
@@ -259,31 +260,6 @@ def start_pytest_item(self, test_item=None):
259260
self.log_item_id = item_id
260261
return item_id
261262

262-
def is_item_update_supported(self):
263-
"""Check item update API call client support."""
264-
return hasattr(self.rp, "update_test_item")
265-
266-
def update_pytest_item(self, test_item=None):
267-
"""Make item update API call.
268-
269-
:param test_item: pytest test item
270-
"""
271-
self._stop_if_necessary()
272-
if self.rp is None:
273-
return
274-
275-
# if update_test_item is not supported in client
276-
if not self.is_item_update_supported():
277-
log.debug('ReportPortal - Update TestItem: method is not defined')
278-
return
279-
280-
start_rq = {
281-
'description': self._get_item_description(test_item),
282-
'tags': self._get_item_tags(test_item),
283-
}
284-
log.debug('ReportPortal - Update TestItem: request_body=%s', start_rq)
285-
self.rp.update_test_item(**start_rq)
286-
287263
def finish_pytest_item(self, test_item, item_id, status, issue=None):
288264
self._stop_if_necessary()
289265
if self.rp is None:
@@ -473,7 +449,7 @@ def _get_item_dirs(item):
473449

474450
return dir_list
475451

476-
def _get_item_tags(self, item):
452+
def _get_item_markers(self, item):
477453
# Try to extract names of @pytest.mark.* decorators used for test item
478454
# and exclude those which present in rp_ignore_tags parameter
479455
def get_marker_value(item, keyword):
@@ -487,17 +463,15 @@ def get_marker_value(item, keyword):
487463
if marker and marker.args else keyword
488464

489465
try:
490-
tags = [get_marker_value(item, k) for k in item.keywords
491-
if item.get_closest_marker(k) is not None
492-
and k not in self.ignored_tags]
466+
get_marker = getattr(item, "get_closest_marker")
493467
except AttributeError:
494-
# pytest < 3.6
495-
tags = [get_marker_value(item, k) for k in item.keywords
496-
if item.get_marker(k) is not None
497-
and k not in self.ignored_tags]
498-
499-
tags.extend(item.session.config.getini('rp_tests_tags'))
468+
get_marker = getattr(item, "get_marker")
469+
tags = [{"value": get_marker_value(item, k)}
470+
for k in item.keywords if get_marker(k) is not None
471+
and k not in self.ignored_tags]
500472

473+
tags.extend([{"value": tag}
474+
for tag in item.session.config.getini('rp_tests_tags')])
501475
return tags
502476

503477
def _get_parameters(self, item):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def read_file(fname):
1212

1313

1414
requirements = [
15-
'reportportal-client~=5.0.0',
15+
'reportportal-client>=5.0.2',
1616
'pytest>=3.0.7',
1717
'six>=1.10.0',
1818
'dill>=0.2.7.1',

tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ def mocked_session(mocked_config):
4040
return mocked_session
4141

4242

43-
@fixture(scope='session')
43+
@fixture()
4444
def rp_listener(rp_service):
4545
"""Prepare instance of the RPReportListener for testing."""
4646
return RPReportListener(rp_service)
4747

4848

49-
@fixture(scope='session')
49+
@fixture()
5050
def rp_service():
5151
"""Prepare instance of the PyTestServiceClass for testing."""
5252
service = PyTestServiceClass()

tests/test_plugin.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,6 @@ def test_pytest_runtest_protocol(mocked_item):
7474
assert_expectations()
7575

7676

77-
def test_is_item_update_supported(rp_service):
78-
"""Test listener public is_client_support_item_update method.
79-
80-
:param rp_service: Pytest fixture
81-
"""
82-
func = None
83-
84-
if hasattr(rp_service.rp, 'update_test_item'):
85-
func = rp_service.rp.update_test_item
86-
delattr(type(rp_service.rp), 'update_test_item')
87-
88-
result = rp_service.is_item_update_supported()
89-
expect(result is False,
90-
"incorrect result for is_client_support_item_update method")
91-
92-
rp_service.rp.update_test_item = func
93-
setattr(rp_service.rp, 'update_test_item', mock.Mock())
94-
95-
result = rp_service.is_item_update_supported()
96-
expect(result is True,
97-
'incorrect result for is_client_support_item_update method')
98-
assert_expectations()
99-
100-
10177
def test_add_issue_info(rp_listener, rp_service):
10278
"""Test listener helper _add_issue_info method.
10379

tests/test_service.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""This modules includes unit tests for the service.py module."""
2+
3+
from six.moves import mock
4+
5+
import pytest
6+
7+
8+
def test_item_tags(rp_service):
9+
"""Test that item tags are generated in a supported way."""
10+
rp_service.is_item_update_supported = mock.Mock(return_value=False)
11+
12+
def getini(option):
13+
if option == 'rp_tests_tags':
14+
return ['ini_marker']
15+
16+
def get_closest_marker(name):
17+
return {'test_marker': pytest.mark.test_marker}.get(name)
18+
19+
class NodeKeywords(object):
20+
_keywords = ['pytestmark', 'ini_marker', 'test_marker']
21+
22+
def __iter__(self):
23+
return iter(self._keywords)
24+
25+
test_item = mock.Mock()
26+
test_item.session.config.getini = getini
27+
test_item.keywords = NodeKeywords()
28+
test_item.get_closest_marker = get_closest_marker
29+
markers = rp_service._get_item_markers(test_item)
30+
assert markers == [{'value': 'test_marker'}, {'value': 'ini_marker'}]

0 commit comments

Comments
 (0)