def load_step_modules(step_paths): """Load step modules with step definitions from step_paths directories.""" from behave import matchers from behave.step_registry import setup_step_decorators step_globals = { "use_step_matcher": matchers.use_step_matcher, "step_matcher": matchers.step_matcher, # -- DEPRECATING } setup_step_decorators(step_globals) # -- Allow steps to import other stuff from the steps dir # NOTE: Default matcher can be overridden in "environment.py" hook. with PathManager(step_paths): default_matcher = matchers.current_matcher for path in step_paths: for name in sorted(os.listdir(path)): if name.endswith(".py"): # -- LOAD STEP DEFINITION: # Reset to default matcher after each step-definition. # A step-definition may change the matcher 0..N times. # ENSURE: Each step definition has clean globals. # try: step_module_globals = step_globals.copy() exec_file(os.path.join(path, name), step_module_globals) matchers.current_matcher = default_matcher
def load_step_definitions(self, extra_step_paths=None): if extra_step_paths is None: extra_step_paths = [] step_globals = { "use_step_matcher": matchers.use_step_matcher, "step_matcher": matchers.step_matcher, # -- DEPRECATING } setup_step_decorators(step_globals) # -- Allow steps to import other stuff from the steps dir # NOTE: Default matcher can be overridden in "environment.py" hook. steps_dir = os.path.join(self.base_dir, self.config.steps_dir) paths = [steps_dir] + list(extra_step_paths) with PathManager(paths): default_matcher = matchers.current_matcher for path in paths: for name in sorted(os.listdir(path)): if name.endswith(".py"): # -- LOAD STEP DEFINITION: # Reset to default matcher after each step-definition. # A step-definition may change the matcher 0..N times. # ENSURE: Each step definition has clean globals. # try: step_module_globals = step_globals.copy() exec_file(os.path.join(path, name), step_module_globals) matchers.current_matcher = default_matcher
def load_steps(self): step_globals = {'use_step_matcher': matchers.use_step_matcher,} setup_step_decorators(step_globals) default_matcher = matchers.current_matcher for file_path in glob.glob(self.config.plugins_dir + '/*/steps.py'): step_module_globals = step_globals.copy() exec_file(file_path, step_module_globals) matchers.current_matcher = default_matcher
def reset_runtime(): """Reset runtime environment. Best effort to reset module data to initial state. """ from behave import step_registry from behave import matchers # -- RESET 1: behave.step_registry step_registry.registry = step_registry.StepRegistry() step_registry.setup_step_decorators(None, step_registry.registry) # -- RESET 2: behave.matchers matchers.ParseMatcher.custom_types = {} matchers.current_matcher = matchers.ParseMatcher
def setup_api_with_step_decorators(module, step_registry): _step_registry.setup_step_decorators(module, step_registry)