Skip to content

Commit f5bbbe0

Browse files
author
Dzmitry Humianiuk
authored
Merge pull request #127 from iivanou/stop_plugin_config
Stop plugin configuration if ReportPortal connection fails
2 parents 3eaa150 + dffe71e commit f5bbbe0

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ python:
99
- "3.5"
1010
- "3.6"
1111
script:
12+
- python setup.py test
1213
- python setup.py -q install
1314

1415
jobs:

pytest_reportportal/plugin.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import dill as pickle
66
import pytest
7+
import requests
78
import time
89
from pytest_reportportal import LAUNCH_WAIT_TIMEOUT
910
from .service import PyTestServiceClass
@@ -127,7 +128,24 @@ def pytest_configure(config):
127128
project = config.getini('rp_project')
128129
endpoint = config.getini('rp_endpoint')
129130
uuid = config.getini('rp_uuid')
131+
ignore_errors = config.getini('rp_ignore_errors')
130132
config._reportportal_configured = all([project, endpoint, uuid])
133+
134+
if config._reportportal_configured and ignore_errors:
135+
try:
136+
verify_ssl = config.getini('rp_verify_ssl')
137+
r = requests.get(
138+
'{0}/api/v1/project/{1}'.format(endpoint, project),
139+
headers={
140+
'Authorization': 'bearer {0}'.format(uuid)
141+
},
142+
verify=verify_ssl
143+
)
144+
r.raise_for_status()
145+
except requests.exceptions.RequestException as exc:
146+
log.exception(exc)
147+
config._reportportal_configured = False
148+
131149
if config._reportportal_configured is False:
132150
return
133151

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[aliases]
2+
test=pytest
3+
14
[metadata]
25
description-file = README.rst
36

@@ -6,3 +9,6 @@ formats=gztar
69

710
[bdist_wheel]
811
universal = 1
12+
13+
[tool:pytest]
14+
addopts=-vv

setup.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def read_file(fname):
1313

1414

1515
requirements = [
16-
'reportportal-client>=3.1.0',
16+
'reportportal-client>=3.2.3',
1717
'pytest>=3.0.7',
1818
'six>=1.10.0',
1919
'dill>=0.2.7.1',
@@ -46,4 +46,9 @@ def read_file(fname):
4646
'pytest_reportportal = pytest_reportportal.plugin',
4747
]
4848
},
49+
setup_requires=['pytest-runner'],
50+
tests_require=[
51+
'pytest',
52+
'delayed-assert'
53+
]
4954
)

tests/__init__.py

Whitespace-only changes.

tests/test_plugin.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""This modules includes unit tests for the plugin."""
2+
3+
from requests.exceptions import RequestException
4+
try:
5+
from unittest.mock import create_autospec, Mock, patch
6+
except ImportError:
7+
from mock import create_autospec, Mock, patch
8+
9+
from _pytest.config import Config
10+
from delayed_assert import expect, assert_expectations
11+
12+
from pytest_reportportal.plugin import pytest_configure
13+
14+
15+
@patch('pytest_reportportal.plugin.requests.get')
16+
def test_stop_plugin_configuration_on_conn_error(mocked_get):
17+
"""Test plugin configuration in case of HTTP error.
18+
19+
The value of the _reportportal_configured attribute of the pytest Config
20+
object should be change to False, stopping plugin configuration, if HTTP
21+
error occurs getting HTTP response from the ReportPortal.
22+
:param mocked_get: Instance of the MagicMock
23+
"""
24+
mocked_config = create_autospec(Config)
25+
mocked_config.return_value._reportportal_configured = True
26+
mock_response = Mock()
27+
mock_response.raise_for_status.side_effect = RequestException()
28+
mocked_get.return_value = mock_response
29+
expect(pytest_configure(mocked_config) is None,
30+
'Received unexpected return value from pytest_configure.')
31+
expect(mocked_config._reportportal_configured is False,
32+
'The value of the _reportportal_configured is not False.')
33+
assert_expectations()

0 commit comments

Comments
 (0)