Is there a way in PyTest to pass command line arguments to conftest.py directly?



  • I know that there is a way to pass args in tests itself like it was shown here, but is there a way to pass in conftest.py directly? I want to configure some common stuff for all tests this way.



  • You can make something like this:

    File: conftest.py

    option = None
    
    def pytest_addoption(parser):
        parser.addoption("--arg", action="store", default="example", help="Option for making some stuff")
    
    def pytest_configure(config):
        global option
        option = config.option
    

    and you can access your argument with option.arg in your conftest file.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2