def after_feature(context: Context, feature: Feature): if "UsesCustomParameters" in feature.tags: # after a feature that uses custom parameters, clear all custom parameters in each agent for agent in ["Acme", "Bob", "Faber", "Mallory"]: context.execute_steps( f'Given "{agent}" is running with parameters ' + '"{}"' )
def execute_scenario_by_steps(ctx: Context, scenario: Scenario) -> None: """Step executor for setup and teardown tagged scenarios Args: ctx: The behave context scenario: The behave scenario object """ # Set an empty list of steps to run parsed_steps = [] # For each step put the step in the parsed list for step in scenario.steps: parsed_steps.append(f"{step.keyword} {step.name}") # check to see if we have a table with our step. If we do make sure we put the headings # and rows into the parsed steps list so we execute the full step if step.table: heading_string = "" for heading in step.table.headings: heading_string += f"{heading}|" parsed_steps.append(f"|{heading_string}") for row in step.table.rows: row_string = "|".join(row.cells) parsed_steps.append(f"|{row_string}|") steps_string = "\n".join(parsed_steps) for step in parsed_steps: print(ansicolor.green(f" {step}")) # noqa print("\n") # noqa ctx.execute_steps(steps_string)
def execute_scenario_by_steps(ctx: Context, scenario: Scenario) -> None: """ This function executes each step in a scenario with the ctx.execute steps method. We are doing this in place of scenario.run(ctx._runner) because that hacks the context runner which confuses the behave reporter and formatter causing assertion errors. This is a much smoother way to run steps in the before and after hook. Args: ctx: The behave context scenario: The behave scenario object """ # Set an empty list of steps to run parsed_steps = [] # For each step put the step in the parsed list for step in scenario.steps: parsed_steps.append(f"{step.keyword} {step.name}") # check to see if we have a table with our step. If we do make sure we put the headings # and rows into the parsed steps list so we execute the full step if step.table: heading_string = "" for heading in step.table.headings: heading_string += f"{heading}|" parsed_steps.append(f"|{heading_string}") for row in step.table.rows: row_string = "|".join(row.cells) parsed_steps.append(f"|{row_string}|") steps_string = "\n".join(parsed_steps) LOGGER.info(f"Steps run in setup or teardown scenario:\n{steps_string}") ctx.execute_steps(steps_string)
def the_files_should_exist(context: runner.Context) -> None: """Check a list of files that should have been created. Args: context: Behave runner context with a list of files. """ for target_file in context.table: context.execute_steps(u'then the file "{}" should exist'.format(target_file["file"]))
def the_file_should_contain(context: runner.Context, target: str, contents: str) -> None: """Check a file contains a given string. Args: context: Behave runner context. target: Name of file to check. contents: Expected contents of file. """ context.execute_steps( """ Then the file "{}" should exist with the contents: ''' {} ''' """.format( target, contents ) )