'Is it possible to pass python behave command-line arguments from file

I wonder, is it possible to pass behave arguments, eg. "-D environment". by default they are taken from the behave file. Maybe there is some way to keep each configuration in a different file? Maybe many behave files? or Such as: behave "path to file with arguments"? At this point i figured out that I could put bash scripts containing various configuration " #!/bin/bash behave ..." I asking because i want easily manage my configurations when I run "behave -..." without editing many arguments



Solution 1:[1]

I think you could take advantage of using custom json configuration files described in behave Advanced Cases section: https://behave.readthedocs.io/en/latest/new_and_noteworthy_v1.2.5.html#advanced-cases

from documentation:

# -- FILE: features/environment.py
import json
import os.path

def before_all(context):
    """Load and update userdata from JSON configuration file."""
    userdata = context.config.userdata
    configfile = userdata.get("configfile", "userconfig.json")
    if os.path.exists(configfile):
        assert configfile.endswith(".json")
        more_userdata = json.load(open(configfile))
        context.config.update_userdata(more_userdata)
        # -- NOTE: Reapplies userdata_defines from command-line, too.

So, if you like to use custom config by specifying it at the command line, you could run it as for example:

behave -D conffile=myconfig.json

Then I would parametrize this line to something like:

myconfigfile = context.config.userdata["conffile"]
configfile = userdata.get("configfile", myconfigfile)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 automationleg