I'm trying to implement a custom option parser into behave config parser but haven't been able to do so.
I am calling behave_runner.py through behave and this is behave_runner.py:
if __name__ == "__main__":
configuration.setup_parser().add_argument('-E', '--env', help="pass in the environment")
sys.exit(__main__.main())
I've tried monkey_patching it which is a no-go either.. --env is what I want to pass in for the config parser to read a section from behave.ini which is like this:
[dev]
username = x
password = xx
server = xxx
[dev2]
username = y
password = yy
server = yyy
so in environment.py, I'm reading the using config parser but I cannot seem to inject my custom option into behave parser, so it doesn't pick up something like behave -E dev
and how do I read it from the custom parser that I've put in with a if configuration.something.something == 'dev'
? I've searched quite many places, and everything points me to userdata which is not something I want to use.
I want this to work something similar to option parser ~ can pass in defaults but not custom stuff. patch fix of #270 in behave is not helping me either.. thanks in advance !
was able to figure out my own answer.. instead of trying adding new options to the config parser, I'm using Environment Variables to set which config-section I want to read from:
import os
env = os.environ.get('ENV', failobj='dev')
if env in 'dev':
//do stuff here
elif env in 'dev2':
//do some other stuff here
And I run this with (in windows):
set ENV=dev
behave
I think using an Environment Variable was a better option for my case... anyhow - just spreading the word for those who is looking for an alternative. Cheers!