11import datetime
2- import os
32import re
43from re import Pattern
5- from typing import TYPE_CHECKING , Any , Callable , Optional , Union , cast , overload
4+ from typing import TYPE_CHECKING , Any , Callable , Optional , Union , cast
65
76import requests
87import urllib3 .exceptions
@@ -55,45 +54,6 @@ def yaml_to_dict(data: str, yaml_type: tmt.utils.YamlTypType = "safe") -> dict[s
5554 return d
5655
5756
58- def _flag_env_to_default (option : str , default : bool ) -> bool :
59- env_var = 'TMT_PLUGIN_REPORT_REPORTPORTAL_' + option .upper ()
60- if env_var not in os .environ :
61- return default
62- return bool (os .getenv (env_var ) == '1' )
63-
64-
65- @overload
66- def _str_env_to_default (option : str , default : None ) -> Optional [str ]:
67- pass
68-
69-
70- @overload
71- def _str_env_to_default (option : str , default : str ) -> str :
72- pass
73-
74-
75- def _str_env_to_default (option : str , default : Optional [str ]) -> Optional [str ]:
76- env_var = 'TMT_PLUGIN_REPORT_REPORTPORTAL_' + option .upper ()
77- if env_var not in os .environ or os .getenv (env_var ) is None :
78- return default
79- return str (os .getenv (env_var ))
80-
81-
82- def _pattern_list_env_to_default (option : str , default : list [Pattern [str ]]) -> list [Pattern [str ]]:
83- env_var = 'TMT_PLUGIN_REPORT_REPORTPORTAL_' + option .upper ()
84- if env_var not in os .environ or os .getenv (env_var ) is None :
85- return default
86- return tmt .utils .normalize_pattern_list (
87- option ,
88- [item .strip () for item in str (os .getenv (env_var )).split (',' ) if item .strip ()],
89- tmt .log .Logger .get_bootstrap_logger (),
90- )
91-
92-
93- def _size_env_to_default (option : str , default : 'Size' ) -> 'Size' :
94- return tmt .hardware .UNITS (_str_env_to_default (option , str (default )))
95-
96-
9757def _normalize_log_size_limit (
9858 key_address : str ,
9959 raw_value : Any ,
@@ -163,28 +123,28 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
163123 url : Optional [str ] = field (
164124 option = "--url" ,
165125 metavar = "URL" ,
166- default = _str_env_to_default ( 'url' , None ) ,
126+ default = None ,
167127 help = "The URL of the ReportPortal instance where the data should be sent to." ,
168128 )
169129
170130 token : Optional [str ] = field (
171131 option = "--token" ,
172132 metavar = "TOKEN" ,
173- default = _str_env_to_default ( 'token' , None ) ,
133+ default = None ,
174134 help = "The token to use for upload to the ReportPortal instance (from the user profile)." ,
175135 )
176136
177137 project : Optional [str ] = field (
178138 option = "--project" ,
179139 metavar = "PROJECT_NAME" ,
180- default = _str_env_to_default ( 'project' , None ) ,
140+ default = None ,
181141 help = "Name of the project into which the results should be uploaded." ,
182142 )
183143
184144 launch : Optional [str ] = field (
185145 option = "--launch" ,
186146 metavar = "LAUNCH_NAME" ,
187- default = _str_env_to_default ( 'launch' , None ) ,
147+ default = None ,
188148 help = """
189149 Set the launch name, otherwise name of the plan is used by default.
190150 Should be defined with 'suite-per-plan' option or it will be named after the first plan.
@@ -194,7 +154,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
194154 launch_description : Optional [str ] = field (
195155 option = "--launch-description" ,
196156 metavar = "DESCRIPTION" ,
197- default = _str_env_to_default ( 'launch_description' , None ) ,
157+ default = None ,
198158 help = """
199159 Pass the description for ReportPortal launch with 'suite-per-plan' option
200160 or append the original (plan summary) with additional info.
@@ -204,14 +164,14 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
204164
205165 launch_per_plan : bool = field (
206166 option = "--launch-per-plan" ,
207- default = _flag_env_to_default ( 'launch_per_plan' , False ) ,
167+ default = False ,
208168 is_flag = True ,
209169 help = "Mapping launch per plan, creating one or more launches with no suite structure." ,
210170 )
211171
212172 suite_per_plan : bool = field (
213173 option = "--suite-per-plan" ,
214- default = _flag_env_to_default ( 'suite_per_plan' , False ) ,
174+ default = False ,
215175 is_flag = True ,
216176 help = """
217177 Mapping suite per plan, creating one launch and continuous uploading suites into it.
@@ -223,7 +183,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
223183 upload_to_launch : Optional [str ] = field (
224184 option = "--upload-to-launch" ,
225185 metavar = "LAUNCH_ID" ,
226- default = _str_env_to_default ( 'upload_to_launch' , None ) ,
186+ default = None ,
227187 help = """
228188 Pass the launch ID for an additional test/suite upload to an existing launch. ID can be
229189 found in the launch URL. Keep the launch structure with options 'launch/suite-per-plan'.
@@ -234,7 +194,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
234194 upload_to_suite : Optional [str ] = field (
235195 option = "--upload-to-suite" ,
236196 metavar = "SUITE_ID" ,
237- default = _str_env_to_default ( 'upload_to_suite' , None ) ,
197+ default = None ,
238198 help = """
239199 Pass the suite ID for an additional test upload to a suite
240200 within an existing launch. ID can be found in the suite URL.
@@ -244,7 +204,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
244204
245205 launch_rerun : bool = field (
246206 option = "--launch-rerun" ,
247- default = _flag_env_to_default ( 'launch_rerun' , False ) ,
207+ default = False ,
248208 is_flag = True ,
249209 help = """
250210 Rerun the last launch based on its name and unique test paths to create Retry item
@@ -255,7 +215,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
255215 defect_type : Optional [str ] = field (
256216 option = "--defect-type" ,
257217 metavar = "DEFECT_NAME" ,
258- default = _str_env_to_default ( 'defect_type' , None ) ,
218+ default = None ,
259219 help = """
260220 Pass the defect type to be used for failed test, which is defined in the project
261221 (e.g. 'Idle'). 'To Investigate' is used by default.
@@ -265,7 +225,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
265225 log_size_limit : 'Size' = field (
266226 option = "--log-size-limit" ,
267227 metavar = "SIZE" ,
268- default = _size_env_to_default ( 'log_size_limit' , DEFAULT_LOG_SIZE_LIMIT ) ,
228+ default = DEFAULT_LOG_SIZE_LIMIT ,
269229 help = f"""
270230 Size limit in bytes for log upload to ReportPortal.
271231 The default limit is { DEFAULT_LOG_SIZE_LIMIT } .
@@ -279,7 +239,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
279239 traceback_size_limit : 'Size' = field (
280240 option = "--traceback-size-limit" ,
281241 metavar = "SIZE" ,
282- default = _size_env_to_default ( 'traceback_size_limit' , DEFAULT_TRACEBACK_SIZE_LIMIT ) ,
242+ default = DEFAULT_TRACEBACK_SIZE_LIMIT ,
283243 help = f"""
284244 Size limit in bytes for traceback log upload to ReportPortal.
285245 The default limit is { DEFAULT_TRACEBACK_SIZE_LIMIT } .
@@ -294,7 +254,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
294254 exclude_variables : str = field (
295255 option = "--exclude-variables" ,
296256 metavar = "PATTERN" ,
297- default = _str_env_to_default ( 'exclude_variables' , "^TMT_.*" ) ,
257+ default = "^TMT_.*" ,
298258 help = """
299259 Regular expression for excluding environment variables
300260 from reporting to ReportPortal ('^TMT_.*' used by default).
@@ -307,14 +267,15 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
307267 api_version : str = field (
308268 option = "--api-version" ,
309269 metavar = "VERSION" ,
310- default = _str_env_to_default ( 'api_version' , "v1" ) ,
270+ default = 'v1' ,
311271 help = "Override the default reportportal API version (v1)." ,
312272 )
313273
314274 artifacts_url : Optional [str ] = field (
315275 metavar = "ARTIFACTS_URL" ,
316276 option = "--artifacts-url" ,
317- default = _str_env_to_default ('artifacts_url' , os .getenv ('TMT_REPORT_ARTIFACTS_URL' )),
277+ envvar = 'TMT_REPORT_ARTIFACTS_URL' ,
278+ default = None ,
318279 help = "Link to test artifacts provided for report plugins." ,
319280 )
320281
@@ -337,7 +298,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
337298 link_template : Optional [str ] = field (
338299 metavar = "TEMPLATE" ,
339300 option = "--link-template" ,
340- default = _str_env_to_default ( 'link_template' , None ) ,
301+ default = None ,
341302 help = """
342303 Jinja template that will be rendered for each test result and appended to the end
343304 of its description. The following variables are passed to the template:
@@ -349,9 +310,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
349310 metavar = "PATTERN" ,
350311 option = "--upload-log-pattern" ,
351312 multiple = True ,
352- default_factory = lambda : _pattern_list_env_to_default (
353- 'upload_log_pattern' , DEFAULT_LOG_PATTERNS [:]
354- ),
313+ default_factory = DEFAULT_LOG_PATTERNS .copy ,
355314 normalize = tmt .utils .normalize_pattern_list ,
356315 serialize = lambda patterns : [pattern .pattern for pattern in patterns ],
357316 unserialize = lambda serialized : [re .compile (pattern ) for pattern in serialized ],
@@ -366,7 +325,7 @@ class ReportReportPortalData(tmt.steps.report.ReportStepData):
366325
367326 auto_analysis : bool = field (
368327 option = "--auto-analysis" ,
369- default = _flag_env_to_default ( 'auto_analysis' , False ) ,
328+ default = False ,
370329 is_flag = True ,
371330 help = """
372331 Enable immediate auto-analysis of failed tests in ReportPortal. When enabled,
0 commit comments