diff --git a/ctf_cli/arguments_parser.py b/ctf_cli/arguments_parser.py index b9ce4d3..ca654ba 100644 --- a/ctf_cli/arguments_parser.py +++ b/ctf_cli/arguments_parser.py @@ -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") diff --git a/ctf_cli/behave.py b/ctf_cli/behave.py index 77ddb02..45e69c0 100644 --- a/ctf_cli/behave.py +++ b/ctf_cli/behave.py @@ -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) @@ -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)]) diff --git a/ctf_cli/config.py b/ctf_cli/config.py index ca2213d..65d9027 100644 --- a/ctf_cli/config.py +++ b/ctf_cli/config.py @@ -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' @@ -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, diff --git a/features/run_params.feature b/features/run_params.feature index 83d8952..38bb2e3 100644 --- a/features/run_params.feature +++ b/features/run_params.feature @@ -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"