Skip to content

Commit

Permalink
Merge pull request #356 from reportportal/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
HardNorth authored Dec 6, 2023
2 parents 50676ac + f524b24 commit 0154506
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 73 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Changelog

## [Unreleased]
### Changed
- Client version updated on [5.5.4](https://github.com/reportportal/client-Python/releases/tag/5.5.4), by @HardNorth
- `rp_launch_id` property handling moved completely on Client side, by @HardNorth

## [5.3.0]
### Added
- `RP_CLIENT_TYPE` configuration variable, by @HardNorth
- `RP_CONNECT_TIMEOUT` and `RP_READ_TIMEOUT` configuration variables, by @HardNorth
- `rp_client_type` configuration variable, by @HardNorth
- `rp_connect_timeout` and `rp_read_timeout` configuration variables, by @HardNorth
### Changed
- Client version updated on [5.5.2](https://github.com/reportportal/client-Python/releases/tag/5.5.2), by @HardNorth

Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ agent-python-pytest
.. image:: https://github.com/reportportal/agent-python-pytest/actions/workflows/tests.yml/badge.svg
:target: https://github.com/reportportal/agent-python-pytest/actions/workflows/tests.yml
:alt: Test status
.. image:: https://codecov.io/gh/reportportal/agent-python-pytest/branch/master/graph/badge.svg
.. image:: https://codecov.io/gh/reportportal/agent-python-pytest/branch/develop/graph/badge.svg
:target: https://codecov.io/gh/reportportal/agent-python-pytest
:alt: Test coverage
.. image:: https://slack.epmrpp.reportportal.io/badge.svg
Expand Down
2 changes: 1 addition & 1 deletion pytest_reportportal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
get_actual_log_level


class AgentConfig(object):
class AgentConfig:
"""Storage for the RP agent initialization attributes."""

rp_client_type: Optional[ClientType]
Expand Down
11 changes: 4 additions & 7 deletions pytest_reportportal/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def pytest_configure_node(node):
if not node.config._rp_enabled:
# Stop now if the plugin is not properly configured
return
node.workerinput['py_test_service'] = pickle.dumps(
node.config.py_test_service)
node.workerinput['py_test_service'] = pickle.dumps(node.config.py_test_service)


def is_control(config):
Expand Down Expand Up @@ -102,7 +101,7 @@ def pytest_sessionstart(session):
config._rp_enabled = False
return

if is_control(config) and not config._reporter_config.rp_launch_id:
if is_control(config):
config.py_test_service.start_launch()
if config.pluginmanager.hasplugin('xdist') \
or config.pluginmanager.hasplugin('pytest-parallel'):
Expand Down Expand Up @@ -137,8 +136,7 @@ def pytest_sessionfinish(session):
return

config.py_test_service.finish_suites()
if is_control(config) \
and not config._reporter_config.rp_launch_id:
if is_control(config):
config.py_test_service.finish_launch()

config.py_test_service.stop()
Expand Down Expand Up @@ -224,8 +222,7 @@ def pytest_configure(config):
config.py_test_service = PyTestServiceClass(agent_config)
else:
# noinspection PyUnresolvedReferences
config.py_test_service = pickle.loads(
config.workerinput['py_test_service'])
config.py_test_service = pickle.loads(config.workerinput['py_test_service'])


# noinspection PyProtectedMember
Expand Down
5 changes: 2 additions & 3 deletions pytest_reportportal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ def _get_launch_attributes(self, ini_attrs):

def _build_start_launch_rq(self):
rp_launch_attributes = self._config.rp_launch_attributes
attributes = gen_attributes(rp_launch_attributes) \
if rp_launch_attributes else None
attributes = gen_attributes(rp_launch_attributes) if rp_launch_attributes else None

start_rq = {
'attributes': self._get_launch_attributes(attributes),
Expand Down Expand Up @@ -909,7 +908,7 @@ def start(self) -> None:
log_batch_size=self._config.rp_log_batch_size,
retries=self._config.rp_api_retries,
verify_ssl=self._config.rp_verify_ssl,
launch_id=launch_id,
launch_uuid=launch_id,
log_batch_payload_size=self._config.rp_log_batch_payload_size,
launch_uuid_print=self._config.rp_launch_uuid_print,
print_output=self._config.rp_launch_uuid_print_output,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
dill>=0.3.6
pytest>=3.8.0
reportportal-client~=5.5.2
reportportal-client~=5.5.4
aenum>=3.1.0
requests>=2.28.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from setuptools import setup


__version__ = '5.3.0'
__version__ = '5.3.1'


def read_file(fname):
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
"""This package contains tests for the project."""

REPORT_PORTAL_SERVICE = 'reportportal_client.RPClient'
REQUESTS_SERVICE = 'reportportal_client.client.requests.Session'
64 changes: 21 additions & 43 deletions tests/integration/test_config_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,33 @@
from unittest import mock

import pytest

from delayed_assert import expect, assert_expectations
from reportportal_client import OutputType

from examples.test_rp_logging import LOG_MESSAGE
from tests import REPORT_PORTAL_SERVICE
from tests import REPORT_PORTAL_SERVICE, REQUESTS_SERVICE
from tests.helpers import utils

TEST_LAUNCH_ID = 'test_launch_id'


@mock.patch(REPORT_PORTAL_SERVICE)
def test_rp_launch_id(mock_client_init):
@mock.patch(REQUESTS_SERVICE)
def test_rp_launch_id(mock_requests_init):
"""Verify that RP plugin does not start/stop launch if 'rp_launch_id' set.
:param mock_client_init: Pytest fixture
:param mock_requests_init: mocked requests lib
"""
variables = dict()
variables['rp_launch_id'] = TEST_LAUNCH_ID
variables.update(utils.DEFAULT_VARIABLES.items())
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
variables=variables)

result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
assert int(result) == 0, 'Exit code should be 0 (no errors)'

expect(
mock_client_init.call_args_list[0][1]['launch_id'] == TEST_LAUNCH_ID)

mock_client = mock_client_init.return_value
expect(mock_client.start_launch.call_count == 0,
'"start_launch" method was called')
expect(mock_client.finish_launch.call_count == 0,
'"finish_launch" method was called')

start_call_args = mock_client.start_test_item.call_args_list
finish_call_args = mock_client.finish_test_item.call_args_list

expect(len(start_call_args) == len(finish_call_args))
assert_expectations()
mock_requests = mock_requests_init.return_value
assert mock_requests.post.call_count == 1
item_start = mock_requests.post.call_args_list[0]
assert item_start[0][0].endswith('/item')
assert item_start[1]['json']['launchUuid'] == TEST_LAUNCH_ID


@mock.patch(REPORT_PORTAL_SERVICE)
Expand All @@ -68,8 +56,7 @@ def test_rp_parent_item_id(mock_client_init):
variables = dict()
variables['rp_parent_item_id'] = parent_id
variables.update(utils.DEFAULT_VARIABLES.items())
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
variables=variables)
result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)

assert int(result) == 0, 'Exit code should be 0 (no errors)'

Expand All @@ -87,34 +74,25 @@ def test_rp_parent_item_id(mock_client_init):
assert_expectations()


@mock.patch(REPORT_PORTAL_SERVICE)
def test_rp_parent_item_id_and_rp_launch_id(mock_client_init):
@mock.patch(REQUESTS_SERVICE)
def test_rp_parent_item_id_and_rp_launch_id(mock_requests_init):
"""Verify RP handles both conf props 'rp_parent_item_id' & 'rp_launch_id'.
:param mock_client_init: Pytest fixture
:param mock_requests_init: mocked requests lib
"""
parent_id = "parent_id"
variables = dict()
variables['rp_parent_item_id'] = parent_id
variables['rp_launch_id'] = "test_launch_id"
variables['rp_launch_id'] = TEST_LAUNCH_ID
variables.update(utils.DEFAULT_VARIABLES.items())
result = utils.run_pytest_tests(tests=['examples/test_simple.py'],
variables=variables)

result = utils.run_pytest_tests(tests=['examples/test_simple.py'], variables=variables)
assert int(result) == 0, 'Exit code should be 0 (no errors)'

mock_client = mock_client_init.return_value
expect(mock_client.start_launch.call_count == 0,
'"start_launch" method was called')
expect(mock_client.finish_launch.call_count == 0,
'"finish_launch" method was called')

start_call_args = mock_client.start_test_item.call_args_list
finish_call_args = mock_client.finish_test_item.call_args_list

expect(len(start_call_args) == len(finish_call_args))
expect(start_call_args[0][1]["parent_item_id"] == parent_id)
assert_expectations()
mock_requests = mock_requests_init.return_value
assert mock_requests.post.call_count == 1
item_start = mock_requests.post.call_args_list[0]
assert item_start[0][0].endswith(f'/item/{parent_id}')
assert item_start[1]['json']['launchUuid'] == TEST_LAUNCH_ID


@mock.patch(REPORT_PORTAL_SERVICE)
Expand Down
24 changes: 10 additions & 14 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@

"""This module includes unit tests for the plugin."""

from _pytest.config.argparsing import Parser
import pytest
from delayed_assert import expect, assert_expectations
from requests.exceptions import RequestException
# noinspection PyUnresolvedReferences
from unittest import mock

import pytest
from _pytest.config.argparsing import Parser
from delayed_assert import expect, assert_expectations
from reportportal_client.errors import ResponseError
from requests.exceptions import RequestException

from pytest_reportportal.config import AgentConfig
from pytest_reportportal.plugin import (
Expand Down Expand Up @@ -258,10 +258,8 @@ def test_pytest_sessionstart(mocked_session):
:param mocked_session: pytest fixture
"""
mocked_session.config.pluginmanager.hasplugin.return_value = True
mocked_session.config._reporter_config = mock.Mock(
spec=AgentConfig(mocked_session.config))
mocked_session.config._reporter_config = mock.Mock(spec=AgentConfig(mocked_session.config))
mocked_session.config._reporter_config.rp_launch_attributes = []
mocked_session.config._reporter_config.rp_launch_id = None
mocked_session.config.py_test_service = mock.Mock()
pytest_sessionstart(mocked_session)
expect(lambda: mocked_session.config.py_test_service.init_service.called)
Expand Down Expand Up @@ -298,22 +296,20 @@ def test_pytest_sessionstart_launch_wait_fail(mocked_log, mocked_session):
)


@mock.patch('pytest_reportportal.plugin.is_control', mock.Mock())
@mock.patch('pytest_reportportal.plugin.wait_launch', mock.Mock())
def test_pytest_sessionstart_with_launch_id(mocked_session):
"""Test session configuration if RP launch ID is set via command-line.
def test_pytest_sessionstart_xdist(mocked_session):
"""Test session configuration if it's worker xdist node.
:param mocked_session: pytest fixture
"""
mocked_session.config.pluginmanager.hasplugin.return_value = True
mocked_session.config._reporter_config = mock.Mock(
spec=AgentConfig(mocked_session.config))
mocked_session.config._reporter_config = mock.Mock(spec=AgentConfig(mocked_session.config))
mocked_session.config._reporter_config.rp_launch_attributes = []
mocked_session.config._reporter_config.rp_launch_id = 1
mocked_session.config.workerinput = 1
mocked_session.config.py_test_service = mock.Mock()
pytest_sessionstart(mocked_session)
expect(lambda: mocked_session.config.py_test_service.start_launch.
assert_not_called())
expect(lambda: mocked_session.config.py_test_service.start_launch.assert_not_called())
assert_expectations()


Expand Down

0 comments on commit 0154506

Please sign in to comment.