def pytest_generate_tests(self, metafunc): fname = metafunc.function.__name__ plugin = pytest.config.getoption('plugin', None) if plugin: plugin = plugin.replace('.', '') data = load_from_yaml(__file__, 'fixtures/{}.yml'.format(plugin)) else: data = load_from_yaml(__file__, 'fixtures/') if fname == 'test_matches': entry_name = 'matches' elif fname == 'test_js_matches': entry_name = 'js_matches' elif fname == 'test_modular_matches': entry_name = 'modular_matches' elif fname == 'test_indicators': entry_name = 'indicators' cases = [] for entry in data: for match in entry.get(entry_name, []): cases.append([entry['plugin'], match]) metafunc.parametrize('plugin_name,match', cases)
def pytest_generate_tests(self, metafunc): fname = metafunc.function.__name__ cases = [] all_plugins = load_plugins() for plugin_package in PLUGIN_PACKAGES: package = plugin_package.split(".")[0] package_dir = find_spec(package).submodule_search_locations[0] test_dir = os.path.join(package_dir, os.pardir, "tests") plugin = metafunc.config.getoption("plugin", None) data = load_from_yaml(test_dir, "plugins/fixtures/") only_dom_matches = fname == "test_dom_matches" # Entry is the full plugin test file evaluated as a dictionary for entry in data: # Each yaml_dict is an entry in matches for yaml_dict in entry["matches"]: # Filter valid matchers if dom matchers are expected if (only_dom_matches and "dom" not in yaml_dict) or ( not only_dom_matches and "dom" in yaml_dict): continue if plugin: # Case if plugin was provided by developer if plugin == entry["plugin"]: p = all_plugins.get(entry["plugin"]) cases.append([p, yaml_dict]) else: p = all_plugins.get(entry["plugin"]) cases.append([p, yaml_dict]) metafunc.parametrize("plugin,yaml_dict", cases)
def pytest_generate_tests(self, metafunc): fname = metafunc.function.__name__ cases = [] all_plugins = load_plugins() for plugin_package in PLUGIN_PACKAGES: package = plugin_package.split('.')[0] package_dir = find_spec(package).submodule_search_locations[0] test_dir = os.path.join(package_dir, os.pardir, 'tests') plugin = pytest.config.getoption('plugin', None) if plugin: plugin = plugin.replace('.', '') try: fixture_file = 'plugins/fixtures/{}.yml'.format(plugin) data = load_from_yaml(test_dir, fixture_file) except FileNotFoundError: continue else: data = load_from_yaml(test_dir, 'plugins/fixtures/') if fname == 'test_version_matches': entry_name = 'matches' elif fname == 'test_js_matches': entry_name = 'js_matches' elif fname == 'test_modular_matches': entry_name = 'modular_matches' elif fname == 'test_indicators': entry_name = 'indicators' for entry in data: for yaml_dict in entry.get(entry_name, []): plugin = all_plugins.get(entry['plugin']) cases.append([plugin, yaml_dict]) metafunc.parametrize('plugin,yaml_dict', cases)