def main(args=None): """Main function to run behave (as program). :param args: Command-line args (or string) to use. :return: 0, if successful. Non-zero, in case of errors/failures. """ config = Configuration(args) return run_behave(config, BTWRunner)
def _execute_feature_files(self, args): for test in self.tests: self.xterm_message('%s' % (test)) config = behave.configuration.Configuration(["-f", "null", "--no-summary", "%s.feature" % (test)]) runner = behave.runner.Runner result = run_behave(config, runner) self.xterm_message('%s' % (test), Fore.GREEN, style=Style.NORMAL, oldmsg='%s' % (test)) print('')
def handle(self, *args, **options): # Check the flags if options["use_existing_database"] and options["simple"]: self.stderr.write( self.style.WARNING( "--simple flag has no effect" " together with --use-existing-database" ) ) # Configure django environment passthru_args = ("failfast", "interactive", "keepdb", "reverse") runner_args = { k: v for k, v in options.items() if k in passthru_args and v is not None } if options["dry_run"] or options["use_existing_database"]: django_test_runner = ExistingDatabaseTestRunner(**runner_args) elif options["simple"]: django_test_runner = SimpleTestRunner(**runner_args) else: BehaviorDrivenTestRunner.testcase_class.host = options["host"] BehaviorDrivenTestRunner.testcase_class.port = options["port"] django_test_runner = BehaviorDrivenTestRunner(**runner_args) django_test_runner.setup_test_environment() old_config = django_test_runner.setup_databases() # Run Behave tests monkey_patch_behave(django_test_runner) behave_args = self.get_behave_args() for app in apps.get_app_configs(): feature_dir = Path(app.path) / "features" if feature_dir.exists(): behave_args.append(feature_dir) behave_config = Configuration(behave_args) exit_status = run_behave(behave_config, runner_class=BehaveRunner) # Teardown django environment django_test_runner.teardown_databases(old_config) django_test_runner.teardown_test_environment() if exit_status != 0: sys.exit(exit_status)
def call_executor(self): """Calls the Behave executor to run the scenarios""" run_behave(self.behave_config)
def execute_bdd(statechart: Statechart, feature_filepaths: List[str], *, step_filepaths: List[str] = None, property_statecharts: List[Statechart] = None, interpreter_klass: Callable[[Statechart], Interpreter] = Interpreter, debug_on_error: bool = False, behave_parameters: List[str] = None) -> int: """ Execute BDD tests for a statechart. :param statechart: statechart to test :param feature_filepaths: list of filepaths to feature files. :param step_filepaths: list of filepaths to step definitions. :param property_statecharts: list of property statecharts :param interpreter_klass: a callable that accepts a statechart and an optional clock and returns an Interpreter :param debug_on_error: set to True to drop to (i)pdb in case of error. :param behave_parameters: additional CLI parameters used by Behave (see http://behave.readthedocs.io/en/latest/behave.html#command-line-arguments) :return: exit code of behave CLI. """ # Default values step_filepaths = step_filepaths if step_filepaths else [] property_statecharts = property_statecharts if property_statecharts else [] behave_parameters = behave_parameters if behave_parameters else [] # If debug_on_error, disable captured stdout, otherwise it hangs if debug_on_error and '--capture' not in behave_parameters: behave_parameters.append('--no-capture') # Create temporary directory to put everything inside with tempfile.TemporaryDirectory() as tempdir: # Create configuration for Behave config = Configuration(behave_parameters) # Paths to features config.paths = feature_filepaths # Copy environment with open(os.path.join(tempdir, 'environment.py'), 'w') as environment: environment.write('from sismic.bdd.environment import *') # Path to environment config.environment_file = os.path.join(tempdir, 'environment.py') # Add predefined steps os.mkdir(os.path.join(tempdir, 'steps')) with open(os.path.join(tempdir, 'steps', '__steps.py'), 'w') as step: step.write('from sismic.bdd.steps import *') # Copy provided steps, if any for step_filepath in step_filepaths: shutil.copy(step_filepath, os.path.join( tempdir, 'steps', os.path.split(step_filepath)[-1])) # Path to steps config.steps_dir = os.path.join(tempdir, 'steps') # Put statechart and properties in user data config.update_userdata({ 'statechart': statechart, 'interpreter_klass': interpreter_klass, 'property_statecharts': property_statecharts, 'debug_on_error': debug_on_error, }) # Run behave return run_behave(config)