Skip to content

Commit 9d229e3

Browse files
committed
Add behave-opts cli param to pass arbitrary behave options
1 parent 3330c56 commit 9d229e3

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

ctf_cli/arguments_parser.py

+8
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def add_run_subparser(self):
104104
dest='junit',
105105
help="Junit folder to store results. If not passed junit reports will not be generated"
106106
)
107+
run_subparser.add_argument(
108+
"-o",
109+
"--behave-opts",
110+
action='append',
111+
default=None,
112+
dest='behave_opts',
113+
help="Pass other arguments to behave"
114+
)
107115

108116
def add_update_subparser(self):
109117
self.subparsers.add_parser('update', help="update suites")

ctf_cli/behave.py

+11
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ def run(self):
341341
except Exception:
342342
pass
343343

344+
behave_opts = None
345+
try:
346+
behave_opts = self._cli_conf_obj.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_BEHAVE_OPTS)
347+
except Exception:
348+
pass
349+
344350
verbose = None
345351
try:
346352
verbose = self._cli_conf_obj.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_VERBOSE)
@@ -381,6 +387,11 @@ def run(self):
381387
if verbose != "yes":
382388
command.append('--no-skipped')
383389

390+
if behave_opts:
391+
if type(behave_opts) is str:
392+
behave_opts = behave_opts.split()
393+
command.extend(behave_opts)
394+
384395
if ansible_conf:
385396
command.extend(['-D', 'ANSIBLE={0}'.format(ansible_conf)])
386397

ctf_cli/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class CTFCliConfig(object):
3636
CONFIG_TESTS_CONFIG_PATH = 'TestsConfigPath'
3737
CONFIG_BEHAVE_DATA = 'BehaveData'
3838
CONFIG_BEHAVE_TAGS = 'BehaveTags'
39+
CONFIG_BEHAVE_OPTS = 'BehaveOpts'
3940
CONFIG_JUNIT = 'Junit'
4041
CONFIG_EXEC_TYPE = 'ExecType'
4142
CONFIG_REMOTE_TYPE = 'remote_type'
@@ -101,6 +102,7 @@ def _add_commandline_arguments(self, cli_conf):
101102
cli_conf.tests_config_path)if cli_conf.tests_config_path else None,
102103
self.CONFIG_BEHAVE_DATA: cli_conf.behave_data,
103104
self.CONFIG_BEHAVE_TAGS: cli_conf.behave_tags,
105+
self.CONFIG_BEHAVE_OPTS: cli_conf.behave_opts,
104106
self.CONFIG_JUNIT: cli_conf.junit,
105107
self.CONFIG_EXEC_TYPE: 'ansible',
106108
self.CONFIG_REMOTE_TYPE: cli_conf.remote_type,

features/run_params.feature

+30
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ Feature: Run parameters
4949
INFO: Running behave inside working directory 'behave -v -t tag1 -t ~tag2 -D
5050
"""
5151

52+
Scenario: Behave opts
53+
Given a directory named "features"
54+
And a file named "features/foo.feature" with:
55+
"""
56+
Feature: test feature
57+
58+
Scenario: First scenario
59+
60+
Scenario: Second scenario
61+
62+
Scenario: Third scenario
63+
"""
64+
When I successfully run "ctf run --behave-opts 'features/foo.feature:5'"
65+
Then the command output should contain:
66+
"""
67+
INFO: Running behave inside working directory 'behave features/foo.feature:5'
68+
"""
69+
And the command output should contain:
70+
"""
71+
Scenario: Second scenario
72+
"""
73+
And the command output should not contain:
74+
"""
75+
Scenario: First scenario
76+
"""
77+
And the command output should not contain:
78+
"""
79+
Scenario: Third scenario
80+
"""
81+
5282
Scenario: Run with existing work directory
5383
Given a directory named "workdir"
5484
When I successfully run "ctf -v run"

0 commit comments

Comments
 (0)