Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add behave-opts cli param to pass arbitrary behave options #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ctf_cli/arguments_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def add_run_subparser(self):
dest='junit',
help="Junit folder to store results. If not passed junit reports will not be generated"
)
run_subparser.add_argument(
"-o",
"--behave-opts",
action='append',
default=None,
dest='behave_opts',
help="Pass other arguments to behave"
)

def add_update_subparser(self):
self.subparsers.add_parser('update', help="update suites")
Expand Down
11 changes: 11 additions & 0 deletions ctf_cli/behave.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ def run(self):
except Exception:
pass

behave_opts = None
try:
behave_opts = self._cli_conf_obj.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_BEHAVE_OPTS)
except Exception:
pass

verbose = None
try:
verbose = self._cli_conf_obj.get(CTFCliConfig.GLOBAL_SECTION_NAME, CTFCliConfig.CONFIG_VERBOSE)
Expand Down Expand Up @@ -381,6 +387,11 @@ def run(self):
if verbose != "yes":
command.append('--no-skipped')

if behave_opts:
if type(behave_opts) is str:
behave_opts = behave_opts.split()
command.extend(behave_opts)

if ansible_conf:
command.extend(['-D', 'ANSIBLE={0}'.format(ansible_conf)])

Expand Down
2 changes: 2 additions & 0 deletions ctf_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CTFCliConfig(object):
CONFIG_TESTS_CONFIG_PATH = 'TestsConfigPath'
CONFIG_BEHAVE_DATA = 'BehaveData'
CONFIG_BEHAVE_TAGS = 'BehaveTags'
CONFIG_BEHAVE_OPTS = 'BehaveOpts'
CONFIG_JUNIT = 'Junit'
CONFIG_EXEC_TYPE = 'ExecType'
CONFIG_REMOTE_TYPE = 'remote_type'
Expand Down Expand Up @@ -101,6 +102,7 @@ def _add_commandline_arguments(self, cli_conf):
cli_conf.tests_config_path)if cli_conf.tests_config_path else None,
self.CONFIG_BEHAVE_DATA: cli_conf.behave_data,
self.CONFIG_BEHAVE_TAGS: cli_conf.behave_tags,
self.CONFIG_BEHAVE_OPTS: cli_conf.behave_opts,
self.CONFIG_JUNIT: cli_conf.junit,
self.CONFIG_EXEC_TYPE: 'ansible',
self.CONFIG_REMOTE_TYPE: cli_conf.remote_type,
Expand Down
30 changes: 30 additions & 0 deletions features/run_params.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,36 @@ Feature: Run parameters
INFO: Running behave inside working directory 'behave -v -t tag1 -t ~tag2 -D
"""

Scenario: Behave opts
Given a directory named "tests/features"
And a file named "tests/features/foo.feature" with:
"""
Feature: test feature

Scenario: First scenario

Scenario: Second scenario

Scenario: Third scenario
"""
When I successfully run "ctf run --behave-opts 'tests/features/foo.feature:5'"
Then the command output should contain:
"""
INFO: Running behave inside working directory 'behave tests/features/foo.feature:5'
"""
And the command output should contain:
"""
Scenario: Second scenario
"""
And the command output should not contain:
"""
Scenario: First scenario
"""
And the command output should not contain:
"""
Scenario: Third scenario
"""

Scenario: Run with existing work directory
Given a directory named "workdir"
When I successfully run "ctf -v run"
Expand Down