1

I'm using pytest plugin - pytest-html

The plugin has an option called '--self-contained-html'. I created my own plugin, that builds on this plugin, and adds another option. I want that, when someone uses my option, the original '--self-contained-html' will be set to True, even if it wasn't supplied

Basically, I want to change the option from:

parser.add_option(
'--self-contained-html',
action='store_true',
defaut=False,
)

to

 parser.add_option(
'--self-contained-html',
action='store_true',
default=<Check_if_parser_option_X_was_given>,
)
rdas
  • 20,604
  • 6
  • 33
  • 46
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 1
    You can't check if some option was passed at the time of defining the options. You'll need to do that after the parsing is done. Set default to `None` & then write the logic to set it to the proper value based on the other options – rdas May 17 '20 at 16:21

1 Answers1

0

you can try the below option to append the --self-contained-html in the existing command-line arguments.Befor doing so you can put a condition to check if the option set by you is present in the existing list of command-line arguments.

def pytest_cmdline_preparse(config, args):
    if <option_X> in args:
        args.extend(['--self-contained-html'])
Rohit
  • 376
  • 3
  • 9