2424import pytest
2525
2626# noinspection PyPackageRequirements
27- import requests
2827from pytest import Item , Session
2928from reportportal_client import RP , RPLogHandler
3029from reportportal_client .errors import ResponseError
4847
4948LOGGER : Logger = logging .getLogger (__name__ )
5049
51- MANDATORY_PARAMETER_MISSED_PATTERN : str = (
52- "One of the following mandatory parameters is unset: "
53- + "rp_project: {}, "
54- + "rp_endpoint: {}, "
55- + "rp_api_key: {}"
56- )
57-
5850FAILED_LAUNCH_WAIT : str = (
5951 "Failed to initialize reportportal-client service. "
6052 + "Waiting for Launch start timed out. "
@@ -182,25 +174,6 @@ def register_markers(config) -> None:
182174 config .addinivalue_line ("markers" , "name(name): report the test case with a custom Name." )
183175
184176
185- def check_connection (agent_config : AgentConfig ):
186- """Check connection to RP using provided options.
187-
188- If connection is successful returns True either False.
189- :param agent_config: Instance of the AgentConfig class
190- :return True on successful connection check, either False
191- """
192- url = "{0}/api/v1/project/{1}" .format (agent_config .rp_endpoint , agent_config .rp_project )
193- headers = {"Authorization" : "bearer {0}" .format (agent_config .rp_api_key )}
194- try :
195- resp = requests .get (url , headers = headers , verify = agent_config .rp_verify_ssl )
196- resp .raise_for_status ()
197- return True
198- except requests .exceptions .RequestException as exc :
199- LOGGER .exception (exc )
200- LOGGER .error ("Unable to connect to Report Portal, the launch won't be reported" )
201- return False
202-
203-
204177# no 'config' type for backward compatibility for older pytest versions
205178# noinspection PyProtectedMember
206179def pytest_configure (config ) -> None :
@@ -210,30 +183,17 @@ def pytest_configure(config) -> None:
210183 """
211184 register_markers (config )
212185
186+ agent_config = AgentConfig (config )
187+
213188 config ._rp_enabled = not (
214189 config .getoption ("--collect-only" , default = False )
215190 or config .getoption ("--setup-plan" , default = False )
216- or not config . option .rp_enabled
191+ or not agent_config .rp_enabled
217192 )
218193 if not config ._rp_enabled :
219- return
220-
221- agent_config = AgentConfig (config )
222-
223- cond = (agent_config .rp_project , agent_config .rp_endpoint , agent_config .rp_api_key )
224- config ._rp_enabled = all (cond )
225- if not config ._rp_enabled :
226- LOGGER .debug (MANDATORY_PARAMETER_MISSED_PATTERN .format (* cond ))
227194 LOGGER .debug ("Disabling reporting to RP." )
228195 return
229196
230- if not agent_config .rp_skip_connection_test :
231- config ._rp_enabled = check_connection (agent_config )
232-
233- if not config ._rp_enabled :
234- LOGGER .debug ("Failed to establish connection with RP. " "Disabling reporting." )
235- return
236-
237197 config ._reporter_config = agent_config
238198
239199 if is_control (config ):
@@ -612,6 +572,19 @@ def add_shared_option(name, help_str, default=None, action="store"):
612572 name = "rp_launch_uuid_print_output" ,
613573 help_str = "Launch UUID print output. Default `stdout`. Possible values: [stderr, stdout]" ,
614574 )
575+ add_shared_option (
576+ name = "rp_enabled" ,
577+ help_str = "Enable reportportal plugin" ,
578+ default = True ,
579+ )
580+
581+ # OAuth 2.0 parameters
582+ parser .addini ("rp_oauth_uri" , type = "args" , help = "OAuth 2.0 token endpoint URL for password grant authentication" )
583+ parser .addini ("rp_oauth_username" , type = "args" , help = "OAuth 2.0 username for password grant authentication" )
584+ parser .addini ("rp_oauth_password" , type = "args" , help = "OAuth 2.0 password for password grant authentication" )
585+ parser .addini ("rp_oauth_client_id" , type = "args" , help = "OAuth 2.0 client identifier" )
586+ parser .addini ("rp_oauth_client_secret" , type = "args" , help = "OAuth 2.0 client secret" )
587+ parser .addini ("rp_oauth_scope" , type = "args" , help = "OAuth 2.0 access token scope" )
615588
616589 parser .addini ("rp_launch_attributes" , type = "args" , help = "Launch attributes, i.e Performance Regression" )
617590 parser .addini ("rp_tests_attributes" , type = "args" , help = "Attributes for all tests items, e.g. Smoke" )
@@ -669,7 +642,6 @@ def add_shared_option(name, help_str, default=None, action="store"):
669642 parser .addini ("rp_issue_id_marks" , type = "bool" , default = True , help = "Add tag with issue id to the test" )
670643 parser .addini ("retries" , default = "0" , help = "Deprecated: use `rp_api_retries` instead" )
671644 parser .addini ("rp_api_retries" , default = "0" , help = "Amount of retries for performing REST calls to RP server" )
672- parser .addini ("rp_skip_connection_test" , default = False , type = "bool" , help = "Skip Report Portal connection test" )
673645 parser .addini (
674646 "rp_launch_timeout" ,
675647 default = 86400 ,
0 commit comments