0

I am trying to set a new argument in my test suite and I would like to pass it along pytest commands (e.g. pytest --arg=foo, or pytest --arg=bar path/to/test.py::test_func). Then, those arguments must be used inside some other module. Not test one.

I tried with sys.argv as it is the easiest method and I only need one argument.

q30a
  • 1
  • 3

1 Answers1

0

To import into Python Scripts you need to parse arguments.

#!/usr/bin/env python
import argparse

def main(def_args=sys.argv[1:]):
    args = arguments(def_args)
    user_name = args.user_name
    ....
    //Rest of code


def arguments(argsval):
    parser = argparse.ArgumentParser()
    parser.add_argument('-un', '--user_name', type=str, required=False,
                        help="""Overrides user.name git config.
                        If not specified, the global config is used.""")

Then pass your args in your pytest file.

How to pass arguments in pytest by command line

HXavS
  • 119
  • 7