Skip to content

Commit c055416

Browse files
committed
Test fixes
1 parent c419a22 commit c055416

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

pytest_reportportal/plugin.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
'rp_endpoint: {}, ' + \
3939
'rp_uuid: {}'
4040

41+
FAILED_LAUNCH_WAIT = 'Failed to initialize reportportal-client service. ' \
42+
+ 'Waiting for Launch start timed out. ' \
43+
+ 'Reporting is disabled.'
44+
4145

4246
@pytest.mark.optionalhook
4347
def pytest_configure_node(node):
@@ -103,9 +107,7 @@ def pytest_sessionstart(session):
103107
if config.pluginmanager.hasplugin('xdist') \
104108
or config.pluginmanager.hasplugin('pytest-parallel'):
105109
if not wait_launch(session.config.py_test_service.rp):
106-
log.error('Failed to initialize reportportal-client service. '
107-
'Waiting for Launch start timed out. '
108-
'Reporting is disabled.')
110+
log.error(FAILED_LAUNCH_WAIT)
109111
config.py_test_service.rp = None
110112
config._rp_enabled = False
111113

pytest_reportportal/plugin.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from xdist.workermanage import WorkerController
1212

1313
log: Logger
1414
MANDATORY_PARAMETER_MISSED_PATTERN: Text
15+
FAILED_LAUNCH_WAIT: Text
1516

1617
def check_connection(agent_config: AgentConfig) -> bool: ...
1718
def is_control(config: Config) -> bool: ...

tests/unit/test_plugin.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
pytest_sessionstart,
3333
pytest_sessionfinish,
3434
wait_launch,
35-
MANDATORY_PARAMETER_MISSED_PATTERN
35+
MANDATORY_PARAMETER_MISSED_PATTERN, FAILED_LAUNCH_WAIT
3636
)
3737
from pytest_reportportal.service import PyTestServiceClass
3838

@@ -235,9 +235,7 @@ def test_wait_launch(time_mock):
235235
time_mock.time.side_effect = [0, 1, 2]
236236
rp_client = mock.Mock()
237237
rp_client.launch_id = None
238-
with pytest.raises(Exception) as err:
239-
wait_launch(rp_client)
240-
assert str(err.value) == 'Launch has not started.'
238+
assert not wait_launch(rp_client)
241239

242240

243241
def test_pytest_collection_finish(mocked_session):
@@ -251,12 +249,12 @@ def test_pytest_collection_finish(mocked_session):
251249
assert_called_with(mocked_session)
252250

253251

252+
@mock.patch('pytest_reportportal.plugin.wait_launch',
253+
mock.Mock(return_value=True))
254254
@mock.patch('pytest_reportportal.plugin.is_control', mock.Mock())
255-
@mock.patch('pytest_reportportal.plugin.wait_launch')
256-
def test_pytest_sessionstart(mocked_wait, mocked_session):
255+
def test_pytest_sessionstart(mocked_session):
257256
"""Test session configuration if RP plugin is correctly configured.
258257
259-
:param mocked_wait: Mocked wait_launch function
260258
:param mocked_session: pytest fixture
261259
"""
262260
mocked_session.config.pluginmanager.hasplugin.return_value = True
@@ -269,10 +267,34 @@ def test_pytest_sessionstart(mocked_wait, mocked_session):
269267
expect(lambda: mocked_session.config.py_test_service.init_service.called)
270268
expect(lambda: mocked_session.config.py_test_service.rp is not None)
271269
expect(lambda: mocked_session.config.py_test_service.start_launch.called)
272-
expect(lambda: mocked_wait.called)
273270
assert_expectations()
274271

275272

273+
@mock.patch('pytest_reportportal.plugin.log', wraps=log)
274+
@mock.patch('pytest_reportportal.plugin.is_control', mock.Mock())
275+
@mock.patch('pytest_reportportal.plugin.wait_launch',
276+
mock.Mock(return_value=False))
277+
def test_pytest_sessionstart_launch_wait_fail(mocked_log, mocked_session):
278+
"""Test session configuration if RP plugin is correctly configured.
279+
280+
:param mocked_session: pytest fixture
281+
"""
282+
mocked_session.config.pluginmanager.hasplugin.return_value = True
283+
mocked_session.config._reporter_config = mock.Mock(
284+
spec=AgentConfig(mocked_session.config))
285+
mocked_session.config._reporter_config.rp_launch_attributes = []
286+
mocked_session.config._reporter_config.rp_launch_id = None
287+
mocked_session.config.py_test_service = mock.Mock()
288+
pytest_sessionstart(mocked_session)
289+
expect(lambda: mocked_session.config.py_test_service.rp is None)
290+
assert_expectations()
291+
mocked_log.error.assert_has_calls(
292+
[
293+
mock.call(FAILED_LAUNCH_WAIT)
294+
]
295+
)
296+
297+
276298
@mock.patch('pytest_reportportal.plugin.is_control', mock.Mock())
277299
@mock.patch('pytest_reportportal.plugin.wait_launch', mock.Mock())
278300
def test_pytest_sessionstart_with_launch_id(mocked_session):

0 commit comments

Comments
 (0)