1+ """This module contains changed pytest for report-portal."""
2+
13# This program is free software: you can redistribute it
24# and/or modify it under the terms of the GPL licence
35
3032
3133def is_master (config ):
3234 """
33- True if the code running the given pytest.config object is running in a xdist master
34- node or not running xdist at all.
35+ Validate slaveinput attribute.
36+
37+ True if the code running the given pytest.config object
38+ is running in a xdist master node or not running xdist at all.
3539 """
3640 return not hasattr (config , 'slaveinput' )
3741
3842
3943@pytest .mark .optionalhook
4044def pytest_configure_node (node ):
45+ """
46+ Configure node of tests.
47+
48+ :param node: _pytest.nodes.Node
49+ :return: pickle of RPService
50+ """
4151 if node .config ._reportportal_configured is False :
4252 # Stop now if the plugin is not properly configured
4353 return
44- node .slaveinput ['py_test_service' ] = pickle .dumps (node .config .py_test_service )
54+ node .slaveinput ['py_test_service' ] = pickle .dumps (node .config .
55+ py_test_service )
4556
4657
4758def pytest_sessionstart (session ):
59+ """
60+ Start test session.
61+
62+ :param session: Session
63+ :return: None
64+ """
4865 if session .config ._reportportal_configured is False :
4966 # Stop now if the plugin is not properly configured
5067 return
@@ -73,6 +90,12 @@ def pytest_sessionstart(session):
7390
7491
7592def pytest_collection_finish (session ):
93+ """
94+ Collect tests if session is configured.
95+
96+ :param session: pytest.Session
97+ :return: None
98+ """
7699 if session .config ._reportportal_configured is False :
77100 # Stop now if the plugin is not properly configured
78101 return
@@ -81,6 +104,12 @@ def pytest_collection_finish(session):
81104
82105
83106def wait_launch (rp_client ):
107+ """
108+ Wait for initialize RP_Service.
109+
110+ :param rp_client: RP_Service
111+ :return: None
112+ """
84113 timeout = time .time () + LAUNCH_WAIT_TIMEOUT
85114 while not rp_client .launch_id :
86115 if time .time () > timeout :
@@ -89,6 +118,12 @@ def wait_launch(rp_client):
89118
90119
91120def pytest_sessionfinish (session ):
121+ """
122+ Finish session if has attr 'slaveinput'.
123+
124+ :param session: pytest.Session
125+ :return: None
126+ """
92127 if session .config ._reportportal_configured is False :
93128 # Stop now if the plugin is not properly configured
94129 return
@@ -98,7 +133,12 @@ def pytest_sessionfinish(session):
98133
99134
100135def pytest_configure (config ):
136+ """
137+ Configure RPReportListener for send logs.
101138
139+ :param config: Config file
140+ :return: None
141+ """
102142 if config .getoption ('--collect-only' , default = False ) or \
103143 config .getoption ('--setup-plan' , default = False ) or \
104144 not config .option .rp_enabled :
@@ -132,12 +172,14 @@ def pytest_configure(config):
132172 if not config .option .rp_launch :
133173 config .option .rp_launch = config .getini ('rp_launch' )
134174 if not config .option .rp_launch_description :
135- config .option .rp_launch_description = config .getini ('rp_launch_description' )
175+ config .option .rp_launch_description = config .\
176+ getini ('rp_launch_description' )
136177
137178 if is_master (config ):
138179 config .py_test_service = PyTestServiceClass ()
139180 else :
140- config .py_test_service = pickle .loads (config .slaveinput ['py_test_service' ])
181+ config .py_test_service = pickle .loads (config .
182+ slaveinput ['py_test_service' ])
141183
142184 # set Pytest_Reporter and configure it
143185 if PYTEST_HAS_LOGGING_PLUGIN :
@@ -157,6 +199,12 @@ def pytest_configure(config):
157199
158200
159201def pytest_unconfigure (config ):
202+ """
203+ Clear config from reporter.
204+
205+ :param config: Config file
206+ :return: None
207+ """
160208 if config ._reportportal_configured is False :
161209 # Stop now if the plugin is not properly configured
162210 return
@@ -169,6 +217,12 @@ def pytest_unconfigure(config):
169217
170218
171219def pytest_addoption (parser ):
220+ """
221+ Add parameter in config of reporter.
222+
223+ :param parser: Config
224+ :return: None
225+ """
172226 group = parser .getgroup ('reporting' )
173227 group .addoption (
174228 '--rp-launch' ,
@@ -179,7 +233,8 @@ def pytest_addoption(parser):
179233 '--rp-launch-description' ,
180234 action = 'store' ,
181235 dest = 'rp_launch_description' ,
182- help = 'Launch description (overrides rp_launch_description config option)' )
236+ help = 'Launch description (overrides '
237+ 'rp_launch_description config option)' )
183238
184239 group .addoption (
185240 '--reportportal' ,
@@ -288,7 +343,8 @@ def pytest_addoption(parser):
288343 parser .addini (
289344 'rp_issue_system_url' ,
290345 default = '' ,
291- help = 'URL to get issue description. Issue id from pytest mark will be added to this URL' )
346+ help = 'URL to get issue description. Issue id '
347+ 'from pytest mark will be added to this URL' )
292348
293349 parser .addini (
294350 'rp_verify_ssl' ,
@@ -300,9 +356,12 @@ def pytest_addoption(parser):
300356 'rp_display_suite_test_file' ,
301357 default = True ,
302358 type = 'bool' ,
303- help = "In case of True, include the suite's relative file path in the launch name as a convention of "
304- "'<RELATIVE_FILE_PATH>::<SUITE_NAME>'. In case of False, set the launch name to be the suite name "
305- "only - this flag is relevant only when 'rp_hierarchy_module' flag is set to False" )
359+ help = "In case of True, include the suite's relative"
360+ " file path in the launch name as a convention of "
361+ "'<RELATIVE_FILE_PATH>::<SUITE_NAME>'. "
362+ "In case of False, set the launch name to be the suite name "
363+ "only - this flag is relevant only when"
364+ " 'rp_hierarchy_module' flag is set to False" )
306365
307366 parser .addini (
308367 'rp_issue_id_marks' ,
0 commit comments