How to use commandLine argument from conftest file to other file if we have already import that file in conftest

29 Views Asked by At

We have pytest framework structure given below

enter image description here

In this framework, we have set up command line argument in conftest file

enter image description here

Problem:

We need to access '--ENV' value in config.py file But we have already imported config.py already in conftest.py file. Please suggest the solution for it. and in the config.py we have only variable and assigned values.

I have tried setup and a variable with default value and try to update that variable value with command line argument. config.py:

ENVIRONMENT = "qa"
if hasattr(pytest, 'config') and pytest.config.getoption('--ENV'):
    ENVIRONMENT = pytest.config.getoption('--ENV')
logging.info(ENVIRONMENT)

But in this code value of ENVIRONMENT is not updating during run time and according to command line argument --ENV (command to run program : pytest --ENV QA)

0

There are 0 best solutions below