Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set output and format in python behave, specifically in the environment.py

I can run my behave code with the --format and --outfile parameters, and works as expected.

behave 00-test.feature --format json --outfile "C:/results.json"

Which will give me the results in a json format in C:/results.json.

I want to avoid passing those variables through behave.ini and command line. I want to set those variables in the enviroment.py so I can simply run the following from anywhere:

behave 00-test.feature

Within the environment.py file, I have tried all the combinations I can think of and they all come down to these three variables, but no luck.

def before_all(context):
    ...
    context.config.outfiles = ["C:/results.json"]
    context.config.outputs = [StreamOpener("C:/results.json")]
    context.config.formatters = ['json']
    ...

Why StreamOpener? https://github.com/behave/behave/blob/master/behave/configuration.py shows outputs is a list of StreamOpener objects.

Anybody know the proper way of setting the outfiles and formatters in python-behave?

like image 672
Jack Avatar asked Nov 04 '25 16:11

Jack


1 Answers

Is this a solution? I run it from another module like this

from behave import __main__ as behave_executable
behave_executable.main(args="--format json --outfile results.json")
like image 67
patricmj Avatar answered Nov 07 '25 09:11

patricmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!