|
1 | 1 | """This module includes Service functions for work with pytest agent.""" |
2 | 2 |
|
3 | 3 | import logging |
| 4 | +from os import getenv |
4 | 5 | import sys |
5 | 6 | import traceback |
6 | 7 | from time import time |
|
27 | 28 | from _pytest.unittest import TestCaseFunction, UnitTestCase |
28 | 29 |
|
29 | 30 | from reportportal_client import ReportPortalService |
| 31 | +from reportportal_client.external.google_analytics import send_event |
| 32 | +from reportportal_client.helpers import ( |
| 33 | + gen_attributes, |
| 34 | + get_launch_sys_attrs, |
| 35 | + get_package_version |
| 36 | +) |
30 | 37 | from reportportal_client.service import _dict_to_payload |
31 | 38 | from six import with_metaclass |
32 | 39 | from six.moves import queue |
33 | 40 |
|
34 | | -from .helpers import get_attributes |
35 | 41 |
|
36 | 42 | log = logging.getLogger(__name__) |
37 | 43 |
|
@@ -95,12 +101,14 @@ class PyTestServiceClass(with_metaclass(Singleton, object)): |
95 | 101 |
|
96 | 102 | def __init__(self): |
97 | 103 | """Initialize instance attributes.""" |
98 | | - self._agent_name = 'pytest-reportportal' |
99 | 104 | self._errors = queue.Queue() |
100 | 105 | self._hier_parts = {} |
101 | 106 | self._issue_types = {} |
102 | 107 | self._item_parts = {} |
103 | 108 | self._loglevels = ('TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR') |
| 109 | + self._skip_analytics = getenv('ALLURE_NO_ANALYTICS') |
| 110 | + self.agent_name = 'pytest-reportportal' |
| 111 | + self.agent_version = get_package_version(self.agent_name) |
104 | 112 | self.ignore_errors = True |
105 | 113 | self.ignored_attributes = [] |
106 | 114 | self.log_batch_size = 20 |
@@ -189,6 +197,8 @@ def start_launch(self, |
189 | 197 | log.debug('ReportPortal - Start launch: request_body=%s', sl_pt) |
190 | 198 | item_id = self.rp.start_launch(**sl_pt) |
191 | 199 | log.debug('ReportPortal - Launch started: id=%s', item_id) |
| 200 | + if not self._skip_analytics: |
| 201 | + send_event(self.agent_name, self.agent_version) |
192 | 202 | return item_id |
193 | 203 |
|
194 | 204 | def collect_tests(self, session): |
@@ -604,12 +614,10 @@ def _get_launch_attributes(self, ini_attrs): |
604 | 614 | :param list ini_attrs: List for attributes from the pytest.ini file |
605 | 615 | """ |
606 | 616 | attributes = ini_attrs or [] |
607 | | - |
608 | | - system_info = self.rp.get_system_information(self._agent_name) |
609 | | - system_info['system'] = True |
610 | | - system_attributes = _dict_to_payload(system_info) |
611 | | - |
612 | | - return attributes + system_attributes |
| 617 | + system_attributes = get_launch_sys_attrs() |
| 618 | + system_attributes['agent'] = ( |
| 619 | + '{}-{}'.format(self.agent_name, self.agent_version)) |
| 620 | + return attributes + _dict_to_payload(system_attributes) |
613 | 621 |
|
614 | 622 | def _get_item_markers(self, item): |
615 | 623 | """ |
@@ -639,7 +647,7 @@ def get_marker_value(item, keyword): |
639 | 647 | for k in item.keywords if get_marker(k) is not None |
640 | 648 | and k not in self.ignored_attributes] |
641 | 649 | raw_attrs.extend(item.session.config.getini('rp_tests_attributes')) |
642 | | - return get_attributes(raw_attrs) |
| 650 | + return gen_attributes(raw_attrs) |
643 | 651 |
|
644 | 652 | def _get_parameters(self, item): |
645 | 653 | """ |
|
0 commit comments