Skip to content

Commit 9812c6f

Browse files
committed
wait launch in agent
1 parent e7d5c9e commit 9812c6f

File tree

1 file changed

+13
-43
lines changed

1 file changed

+13
-43
lines changed

pytest_reportportal/plugin.py

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
import logging
55
import dill as pickle
66
import pytest
7+
import time
78
from .service import PyTestServiceClass
89
from .listener import RPReportListener
910

10-
try:
11-
# This try/except can go away once we support pytest >= 3.3
12-
import _pytest.logging
13-
PYTEST_HAS_LOGGING_PLUGIN = True
14-
except ImportError:
15-
PYTEST_HAS_LOGGING_PLUGIN = False
16-
1711

1812
def is_master(config):
1913
"""
@@ -31,7 +25,6 @@ def pytest_configure_node(node):
3125
def pytest_sessionstart(session):
3226
if session.config.getoption('--collect-only', default=False) is True:
3327
return
34-
3528
if is_master(session.config):
3629
session.config.py_test_service.init_service(
3730
project=session.config.getini('rp_project'),
@@ -47,6 +40,16 @@ def pytest_sessionstart(session):
4740
tags=session.config.getini('rp_launch_tags'),
4841
description=session.config.getini('rp_launch_description'),
4942
)
43+
if session.config.pluginmanager.hasplugin('xdist'):
44+
wait_launch(session.config.py_test_service.RP.rp_client.launch_id)
45+
46+
47+
def wait_launch(self):
48+
timeout = time.time() + 10
49+
while not self.rp_client.launch_id:
50+
if time.time() > timeout:
51+
raise Exception("Launch not found")
52+
time.sleep(1)
5053

5154

5255
def pytest_sessionfinish(session):
@@ -62,8 +65,6 @@ def pytest_sessionfinish(session):
6265
def pytest_configure(config):
6366
if not config.option.rp_launch:
6467
config.option.rp_launch = config.getini('rp_launch')
65-
if not config.option.rp_launch_description:
66-
config.option.rp_launch_description = config.getini('rp_launch_description')
6768

6869
if is_master(config):
6970
config.py_test_service = PyTestServiceClass()
@@ -72,20 +73,7 @@ def pytest_configure(config):
7273
config.py_test_service.RP.listener.start()
7374

7475
# set Pytest_Reporter and configure it
75-
76-
if PYTEST_HAS_LOGGING_PLUGIN:
77-
# This check can go away once we support pytest >= 3.3
78-
try:
79-
config._reporter = RPReportListener(
80-
config.py_test_service,
81-
_pytest.logging.get_actual_log_level(config, 'rp_log_level')
82-
)
83-
except TypeError:
84-
# No log level set either in INI or CLI
85-
config._reporter = RPReportListener(config.py_test_service)
86-
else:
87-
config._reporter = RPReportListener(config.py_test_service)
88-
76+
config._reporter = RPReportListener(config.py_test_service)
8977
if hasattr(config, '_reporter'):
9078
config.pluginmanager.register(config._reporter)
9179

@@ -107,24 +95,6 @@ def pytest_addoption(parser):
10795
action='store',
10896
dest='rp_launch',
10997
help='Launch name (overrides rp_launch config option)')
110-
group.addoption(
111-
'--rp-launch-description',
112-
action='store',
113-
dest='rp_launch_description',
114-
help='Launch description (overrides rp_launch_description config option)')
115-
116-
if PYTEST_HAS_LOGGING_PLUGIN:
117-
group.addoption(
118-
'--rp-log-level',
119-
dest='rp_log_level',
120-
default=logging.NOTSET,
121-
help='Logging level for automated log records reporting'
122-
)
123-
parser.addini(
124-
'rp_log_level',
125-
default=logging.NOTSET,
126-
help='Logging level for automated log records reporting'
127-
)
12898

12999
parser.addini(
130100
'rp_uuid',
@@ -167,4 +137,4 @@ def pytest_addoption(parser):
167137
parser.addini(
168138
'rp_ignore_tags',
169139
type='args',
170-
help='Ignore specified pytest markers, i.e parametrize')
140+
help='Ignore specified pytest markers, i.e parametrize')

0 commit comments

Comments
 (0)