def runtest(self): # Load ini first ini_global_cfg_paths = self.config.getini("tavern-global-cfg") or [] # THEN load command line, to allow overwriting of values cmdline_global_cfg_paths = self.config.getoption( "tavern_global_cfg") or [] all_paths = ini_global_cfg_paths + cmdline_global_cfg_paths global_cfg = load_global_config(all_paths) if self.config.getini("tavern-strict") is not None: strict = self.config.getini("tavern-strict") if isinstance(strict, list): if any(i not in ["body", "headers", "redirect_query_params"] for i in strict): raise exceptions.UnexpectedKeysError( "Invalid values for 'strict' use in config file") elif self.config.getoption("tavern_strict") is not None: strict = self.config.getoption("tavern_strict") else: strict = [] global_cfg["strict"] = strict global_cfg["backends"] = {} backends = ["http", "mqtt"] for b in backends: # similar logic to above - use ini, then cmdline if present ini_opt = self.config.getini("tavern-{}-backend".format(b)) cli_opt = self.config.getoption("tavern_{}_backend".format(b)) in_use = ini_opt if cli_opt and (cli_opt != ini_opt): in_use = cli_opt global_cfg["backends"][b] = in_use load_plugins(global_cfg) # INTERNAL xfail = self.spec.get("_xfail", False) try: verify_tests(self.spec) run_test(self.path, self.spec, global_cfg) except exceptions.BadSchemaError: if xfail == "verify": logger.info("xfailing test while verifying schema") else: raise except exceptions.TavernException: if xfail == "run": logger.info("xfailing test when running") else: raise else: if xfail: logger.error("Expected test to fail") raise exceptions.TestFailError
def runtest(self): verify_tests(self.spec) # Load ini first ini_global_cfg_paths = self.config.getini("tavern-global-cfg") or [] # THEN load command line, to allow overwriting of values cmdline_global_cfg_paths = self.config.getoption("tavern_global_cfg") or [] all_paths = ini_global_cfg_paths + cmdline_global_cfg_paths global_cfg = load_global_config(all_paths) run_test(self.path, self.spec, global_cfg)
def _parse_arguments(self): # Load ini first ini_global_cfg_paths = self.config.getini("tavern-global-cfg") or [] # THEN load command line, to allow overwriting of values cmdline_global_cfg_paths = self.config.getoption( "tavern_global_cfg") or [] all_paths = ini_global_cfg_paths + cmdline_global_cfg_paths global_cfg = load_global_config(all_paths) try: loaded_variables = global_cfg["variables"] except KeyError: logger.debug("Nothing to format in global config files") else: tavern_box = Box({"tavern": { "env_vars": dict(os.environ), }}) global_cfg["variables"] = format_keys(loaded_variables, tavern_box) if self.config.getini("tavern-strict") is not None: strict = self.config.getini("tavern-strict") if isinstance(strict, list): if any(i not in ["body", "headers", "redirect_query_params"] for i in strict): raise exceptions.UnexpectedKeysError( "Invalid values for 'strict' use in config file") elif self.config.getoption("tavern_strict") is not None: strict = self.config.getoption("tavern_strict") else: strict = [] global_cfg["strict"] = strict global_cfg["backends"] = {} backends = ["http", "mqtt"] for b in backends: # similar logic to above - use ini, then cmdline if present ini_opt = self.config.getini("tavern-{}-backend".format(b)) cli_opt = self.config.getoption("tavern_{}_backend".format(b)) in_use = ini_opt if cli_opt and (cli_opt != ini_opt): in_use = cli_opt global_cfg["backends"][b] = in_use return global_cfg
def load_global_cfg(pytest_config): """Load globally included config files from cmdline/cfg file arguments Args: pytest_config (pytest.Config): Pytest config object Returns: dict: variables/stages/etc from global config files Raises: exceptions.UnexpectedKeysError: Invalid settings in one or more config files detected """ # Load ini first ini_global_cfg_paths = pytest_config.getini("tavern-global-cfg") or [] # THEN load command line, to allow overwriting of values cmdline_global_cfg_paths = pytest_config.getoption( "tavern_global_cfg") or [] all_paths = ini_global_cfg_paths + cmdline_global_cfg_paths global_cfg = load_global_config(all_paths) try: loaded_variables = global_cfg["variables"] except KeyError: logger.debug("Nothing to format in global config files") else: tavern_box = get_tavern_box() global_cfg["variables"] = format_keys(loaded_variables, tavern_box) # Can be overridden in tests global_cfg["strict"] = _load_global_strictness(pytest_config) global_cfg["follow_redirects"] = _load_global_follow_redirects( pytest_config) global_cfg["backends"] = _load_global_backends(pytest_config) global_cfg["merge_ext_values"] = _load_global_merge_ext(pytest_config) logger.debug("Global config: %s", global_cfg) return global_cfg
def load_global_cfg(pytest_config): """Load globally included config files from cmdline/cfg file arguments Args: pytest_config (pytest.Config): Pytest config object Returns: dict: variables/stages/etc from global config files Raises: exceptions.UnexpectedKeysError: Invalid settings in one or more config files detected """ # Load ini first ini_global_cfg_paths = pytest_config.getini("tavern-global-cfg") or [] # THEN load command line, to allow overwriting of values cmdline_global_cfg_paths = pytest_config.getoption("tavern_global_cfg") or [] all_paths = ini_global_cfg_paths + cmdline_global_cfg_paths global_cfg = load_global_config(all_paths) try: loaded_variables = global_cfg["variables"] except KeyError: logger.debug("Nothing to format in global config files") else: tavern_box = Box({"tavern": {"env_vars": dict(os.environ)}}) global_cfg["variables"] = format_keys(loaded_variables, tavern_box) if pytest_config.getini("tavern-strict") is not None: strict = pytest_config.getini("tavern-strict") if isinstance(strict, list): if any( i not in ["body", "headers", "redirect_query_params"] for i in strict ): raise exceptions.UnexpectedKeysError( "Invalid values for 'strict' use in config file" ) elif pytest_config.getoption("tavern_strict") is not None: strict = pytest_config.getoption("tavern_strict") else: strict = [] global_cfg["strict"] = strict global_cfg["backends"] = {} backends = ["http", "mqtt"] for b in backends: # similar logic to above - use ini, then cmdline if present ini_opt = pytest_config.getini("tavern-{}-backend".format(b)) cli_opt = pytest_config.getoption("tavern_{}_backend".format(b)) in_use = ini_opt if cli_opt and (cli_opt != ini_opt): in_use = cli_opt global_cfg["backends"][b] = in_use logger.debug("Global config: %s", global_cfg) return global_cfg