Skip to content

Commit dedd416

Browse files
authored
Add reporting to GA
1 parent 66398fe commit dedd416

File tree

7 files changed

+36
-51
lines changed

7 files changed

+36
-51
lines changed

README.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Pytest plugin for reporting test results of Pytest to the Reportal Portal.
1212
* Launching
1313
* Send attachement (screenshots)
1414
* Troubleshooting
15+
* Integration with GA
1516
* Copyright Notice
1617

1718
Usage
@@ -253,6 +254,17 @@ deactivate :code:`pytest_reportportal` plugin with command like:
253254
py.test -p no:pytest_reportportal ./tests
254255
255256
257+
Integration with GA
258+
-------------------
259+
ReportPortal is now supporting integrations with more than 15 test frameworks simultaneously. In order to define the most popular agents and plan the team workload accordingly, we are using Google analytics.
260+
261+
ReportPortal collects information about agent name and its version only. This information is sent to Google analytics on the launch start. Please help us to make our work effective.
262+
If you still want to switch Off Google analytics, please change env variable the way below.
263+
264+
.. code-block:: bash
265+
266+
export ALLURE_NO_ANALYTICS=1
267+
256268
257269
Copyright Notice
258270
----------------

pytest_reportportal/helpers.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

pytest_reportportal/plugin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import pytest
1111
import requests
1212
import time
13+
1314
from pytest_reportportal import LAUNCH_WAIT_TIMEOUT
1415
from reportportal_client.errors import ResponseError
16+
from reportportal_client.helpers import gen_attributes
17+
1518
from .service import PyTestServiceClass
1619
from .listener import RPReportListener
17-
from .helpers import get_attributes
1820

1921
try:
2022
# This try/except can go away once we support pytest >= 3.3
@@ -88,7 +90,7 @@ def pytest_sessionstart(session):
8890
session.config.py_test_service.rp = None
8991
return
9092

91-
attributes = get_attributes(
93+
attributes = gen_attributes(
9294
session.config.getini('rp_launch_attributes'))
9395
session.config.py_test_service.start_launch(
9496
session.config.option.rp_launch,

pytest_reportportal/service.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This module includes Service functions for work with pytest agent."""
22

33
import logging
4+
from os import getenv
45
import sys
56
import traceback
67
from time import time
@@ -27,11 +28,16 @@
2728
from _pytest.unittest import TestCaseFunction, UnitTestCase
2829

2930
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+
)
3037
from reportportal_client.service import _dict_to_payload
3138
from six import with_metaclass
3239
from six.moves import queue
3340

34-
from .helpers import get_attributes
3541

3642
log = logging.getLogger(__name__)
3743

@@ -95,12 +101,14 @@ class PyTestServiceClass(with_metaclass(Singleton, object)):
95101

96102
def __init__(self):
97103
"""Initialize instance attributes."""
98-
self._agent_name = 'pytest-reportportal'
99104
self._errors = queue.Queue()
100105
self._hier_parts = {}
101106
self._issue_types = {}
102107
self._item_parts = {}
103108
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)
104112
self.ignore_errors = True
105113
self.ignored_attributes = []
106114
self.log_batch_size = 20
@@ -189,6 +197,8 @@ def start_launch(self,
189197
log.debug('ReportPortal - Start launch: request_body=%s', sl_pt)
190198
item_id = self.rp.start_launch(**sl_pt)
191199
log.debug('ReportPortal - Launch started: id=%s', item_id)
200+
if not self._skip_analytics:
201+
send_event(self.agent_name, self.agent_version)
192202
return item_id
193203

194204
def collect_tests(self, session):
@@ -604,12 +614,10 @@ def _get_launch_attributes(self, ini_attrs):
604614
:param list ini_attrs: List for attributes from the pytest.ini file
605615
"""
606616
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)
613621

614622
def _get_item_markers(self, item):
615623
"""
@@ -639,7 +647,7 @@ def get_marker_value(item, keyword):
639647
for k in item.keywords if get_marker(k) is not None
640648
and k not in self.ignored_attributes]
641649
raw_attrs.extend(item.session.config.getini('rp_tests_attributes'))
642-
return get_attributes(raw_attrs)
650+
return gen_attributes(raw_attrs)
643651

644652
def _get_parameters(self, item):
645653
"""

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
dill>=0.2.7.1
22
pytest>=3.0.7
3-
reportportal-client>=5.0.3
4-
six>=1.13.0
3+
reportportal-client>=5.0.6
4+
six>=1.15.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from setuptools import setup
66

77

8-
__version__ = '5.0.5'
8+
__version__ = '5.0.6'
99

1010

1111
def read_file(fname):

tests/test_helpers.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)