@@ -214,83 +214,80 @@ def pytest_addoption(parser):
214214 :param parser: Object of the Parser class
215215 """
216216 group = parser .getgroup ('reporting' )
217- group .addoption (
218- '--rp-launch' ,
219- action = 'store' ,
220- dest = 'rp_launch' ,
221- help = 'Launch name (overrides rp_launch config option)' )
222- group .addoption (
223- '--rp-launch-id' ,
224- action = 'store' ,
225- dest = 'rp_launch_id' ,
226- help = 'Use already existing launch-id. The plugin won\' t control the '
227- 'Launch status (overrides rp_launch_id config option)' )
228- group .addoption (
229- '--rp-launch-description' ,
230- action = 'store' ,
231- dest = 'rp_launch_description' ,
232- help = 'Launch description (overrides '
233- 'rp_launch_description config option)' )
234- group .addoption (
235- '--rp-rerun' ,
236- action = 'store_true' ,
237- dest = 'rp_rerun' ,
238- help = 'Marks the launch as the rerun' )
239- group .addoption (
240- '--rp-rerun-of' ,
241- action = 'store' ,
242- dest = 'rp_rerun_of' ,
243- help = 'ID of the launch to be marked as a rerun '
244- '(use only with rp_rerun=True)' )
245- group .addoption (
246- '--rp-parent-item-id' ,
247- action = 'store' ,
248- dest = 'rp_parent_item_id' ,
249- help = 'Create all test item as child items of the given '
250- '(already existing) item.' )
251- group .addoption (
252- '--rp-project' ,
253- action = 'store' ,
254- dest = 'rp_project' ,
255- help = 'Sets rp_project from command line'
256- )
217+
218+ def add_shared_option (name , help , default = None , action = 'store' ):
219+ """
220+ Add an option to both the command line and the .ini file.
221+
222+ This function modifies `parser` and `group` from the outer scope.
223+
224+ :param name: name of the option
225+ :param help: help message
226+ :param default: default value
227+ :param action: `group.addoption` action
228+ """
229+ parser .addini (
230+ name = name ,
231+ default = default ,
232+ help = help ,
233+ )
234+ group .addoption (
235+ '--{0}' .format (name .replace ('_' , '-' )),
236+ action = action ,
237+ dest = name ,
238+ help = '{help} (overrides {name} config option)' .format (
239+ help = help ,
240+ name = name ,
241+ ),
242+ )
243+
257244 group .addoption (
258245 '--reportportal' ,
259246 action = 'store_true' ,
260247 dest = 'rp_enabled' ,
261248 default = False ,
262249 help = 'Enable ReportPortal plugin'
263250 )
264- group .addoption (
265- '--rp-log-level' ,
266- dest = 'rp_log_level' ,
267- default = None ,
268- help = 'Logging level for automated log records reporting'
251+ add_shared_option (
252+ name = 'rp_launch' ,
253+ help = 'Launch name' ,
254+ default = 'Pytest Launch' ,
269255 )
270-
271- parser .addini (
272- 'rp_log_level' ,
273- default = None ,
274- help = 'Logging level for automated log records reporting'
256+ add_shared_option (
257+ name = 'rp_launch_id' ,
258+ help = 'Use already existing launch-id. The plugin won\' t control the '
259+ 'Launch status' ,
275260 )
276- parser .addini (
277- 'rp_uuid' ,
278- help = 'UUID' )
279- parser .addini (
280- 'rp_endpoint' ,
281- help = 'Server endpoint' )
282- parser .addini (
283- 'rp_project' ,
284- help = 'Project name' )
285- parser .addini (
286- 'rp_launch' ,
287- default = 'Pytest Launch' ,
288- help = 'Launch name' )
289- parser .addini (
290- 'rp_launch_id' ,
291- default = None ,
292- help = 'Use already existing launch-id. The plugin won\' t control '
293- 'the Launch status' )
261+ add_shared_option (
262+ name = 'rp_launch_description' ,
263+ help = 'Launch description' ,
264+ default = '' ,
265+ )
266+ add_shared_option (name = 'rp_project' , help = 'Project name' )
267+ add_shared_option (
268+ name = 'rp_log_level' ,
269+ help = 'Logging level for automated log records reporting' ,
270+ )
271+ add_shared_option (
272+ name = 'rp_rerun' ,
273+ help = 'Marks the launch as a rerun' ,
274+ default = False ,
275+ action = 'store_true' ,
276+ )
277+ add_shared_option (
278+ name = 'rp_rerun_of' ,
279+ help = 'ID of the launch to be marked as a rerun (use only with '
280+ 'rp_rerun=True)' ,
281+ default = '' ,
282+ )
283+ add_shared_option (
284+ name = 'rp_parent_item_id' ,
285+ help = 'Create all test item as child items of the given (already '
286+ 'existing) item.' ,
287+ )
288+ add_shared_option (name = 'rp_uuid' , help = 'UUID' )
289+ add_shared_option (name = 'rp_endpoint' , help = 'Server endpoint' )
290+
294291 parser .addini (
295292 'rp_launch_attributes' ,
296293 type = 'args' ,
@@ -299,10 +296,6 @@ def pytest_addoption(parser):
299296 'rp_tests_attributes' ,
300297 type = 'args' ,
301298 help = 'Attributes for all tests items, e.g. Smoke' )
302- parser .addini (
303- 'rp_launch_description' ,
304- default = '' ,
305- help = 'Launch description' )
306299 parser .addini (
307300 'rp_log_batch_size' ,
308301 default = '20' ,
@@ -375,21 +368,7 @@ def pytest_addoption(parser):
375368 type = 'bool' ,
376369 default = True ,
377370 help = 'Adding tag with issue id to the test' )
378- parser .addini (
379- 'rp_parent_item_id' ,
380- default = None ,
381- help = "Create all test item as child items of the given "
382- "(already existing) item." )
383371 parser .addini (
384372 'retries' ,
385373 default = '0' ,
386374 help = 'Amount of retries for performing REST calls to RP server' )
387- parser .addini (
388- 'rp_rerun' ,
389- default = False ,
390- help = 'Marks the launch as the rerun' )
391- parser .addini (
392- 'rp_rerun_of' ,
393- default = '' ,
394- help = 'ID of the launch to be marked as a rerun '
395- '(use only with rp_rerun=True)' )
0 commit comments