def resolve_blockers(item, blockers): if not isinstance(blockers, (list, tuple, set)): raise ValueError("Type of the 'blockers' parameter must be one of: list, tuple, set") # Prepare the global env for the kwarg insertion appliance = item.config.pluginmanager.get_plugin('appliance-holder').held_appliance global_env = dict( appliance_version=appliance.version, appliance_downstream=appliance.is_downstream, item=item, blockers=blockers, ) # We will now extend the env with fixtures, so they can be used in the guard functions # We will however add only those that are not in the global_env otherwise we could overwrite # our own stuff. params = extract_fixtures_values(item) for funcarg, value in params.iteritems(): if funcarg not in global_env: global_env[funcarg] = value # Check blockers use_blockers = [] # Bugzilla shortcut blockers = map(lambda b: "BZ#{}".format(b) if isinstance(b, int) else b, blockers) for blocker in map(Blocker.parse, blockers): if blocker.blocks: use_blockers.append(blocker) # Unblocking discard_blockers = set([]) for blocker in use_blockers: unblock_func = kwargify(blocker.kwargs.get("unblock")) local_env = {"blocker": blocker} local_env.update(global_env) if unblock_func(**local_env): discard_blockers.add(blocker) for blocker in discard_blockers: use_blockers.remove(blocker) # We now have those that block testing, so we have to skip # Let's go in the order that they were added # Custom actions first for blocker in use_blockers: if "custom_action" in blocker.kwargs: action = kwargify(blocker.kwargs["custom_action"]) local_env = {"blocker": blocker} local_env.update(global_env) action(**local_env) # And then skip if use_blockers: bugs = [bug.bug_id for bug in use_blockers if hasattr(bug, "bug_id")] skip_data = {'type': 'blocker', 'reason': bugs} fire_art_test_hook(item, 'skip_test', skip_data=skip_data) pytest.skip("Skipping due to these blockers:\n{}".format( "\n".join( "- {}".format(str(blocker)) for blocker in use_blockers ) ))
def resolve_blockers(item, blockers): if not isinstance(blockers, (list, tuple, set)): raise ValueError("Type of the 'blockers' parameter must be one of: list, tuple, set") # Prepare the global env for the kwarg insertion appliance = find_appliance(item) global_env = dict( appliance_version=appliance.version, appliance_downstream=appliance.is_downstream, item=item, blockers=blockers, ) # We will now extend the env with fixtures, so they can be used in the guard functions # We will however add only those that are not in the global_env otherwise we could overwrite # our own stuff. params = extract_fixtures_values(item) for funcarg, value in params.items(): if funcarg not in global_env: global_env[funcarg] = value # Check blockers use_blockers = [] # Bugzilla shortcut blockers = map(lambda b: "BZ#{}".format(b) if isinstance(b, int) else b, blockers) for blocker in map(Blocker.parse, blockers): if blocker.blocks: use_blockers.append(blocker) # Unblocking discard_blockers = set([]) for blocker in use_blockers: unblock_func = kwargify(blocker.kwargs.get("unblock")) local_env = {"blocker": blocker} local_env.update(global_env) if unblock_func(**local_env): discard_blockers.add(blocker) for blocker in discard_blockers: use_blockers.remove(blocker) # We now have those that block testing, so we have to skip # Let's go in the order that they were added # Custom actions first for blocker in use_blockers: if "custom_action" in blocker.kwargs: action = kwargify(blocker.kwargs["custom_action"]) local_env = {"blocker": blocker} local_env.update(global_env) action(**local_env) # And then skip if use_blockers: bugs = [bug.bug_id for bug in use_blockers if hasattr(bug, "bug_id")] skip_data = {'type': 'blocker', 'reason': bugs} fire_art_test_hook(item, 'skip_test', skip_data=skip_data) pytest.skip("Skipping due to these blockers:\n{}".format( "\n".join( "- {}".format(str(blocker)) for blocker in use_blockers ) ))
def uncollectif(item): """ Evaluates if an item should be uncollected Tests markers against a supplied lambda from the markers object to determine if the item should be uncollected or not. """ from cfme.utils.appliance import find_appliance from cfme.utils.pytest_shortcuts import extract_fixtures_values markers = item.get_marker('uncollectif') if not markers: return False, None for mark in markers: log_msg = 'Trying uncollecting {}: {}'.format( item.name, mark.kwargs.get('reason', 'No reason given')) logger.debug(log_msg) try: arg_names = inspect.getargspec(get_uncollect_function(mark)).args except TypeError: logger.debug(log_msg) return not bool(mark.args[0]), mark.kwargs.get( 'reason', 'No reason given') app = find_appliance(item, require=False) if app: global_vars = {'appliance': app} else: logger.info("while uncollecting %s - appliance not known", item) global_vars = {} try: values = extract_fixtures_values(item) values.update(global_vars) # The test has already been uncollected if arg_names and not values: return True, None args = [values[arg] for arg in arg_names] except KeyError: missing_argnames = list( set(arg_names) - set(item._request.funcargnames)) func_name = item.name if missing_argnames: raise Exception( "You asked for a fixture which wasn't in the function {} " "prototype {}".format(func_name, missing_argnames)) else: raise Exception( "Failed to uncollect {}, best guess a fixture wasn't " "ready".format(func_name)) retval = mark.args[0](*args) if retval: # shortcut return retval, mark.kwargs.get('reason', "No reason given") else: return False, None else: return False, None
def uncollectif(item): """ Evaluates if an item should be uncollected Tests markers against a supplied lambda from the markers object to determine if the item should be uncollected or not. """ from cfme.utils.appliance import find_appliance from cfme.utils.pytest_shortcuts import extract_fixtures_values for _, mark in item.iter_markers_with_node('uncollectif') or []: reason = mark.kwargs.get('reason') if reason is None: raise ValueError(REASON_REQUIRED.format(item.name)) log_msg = f'Trying uncollectif {item.name}: {reason}' logger.debug(log_msg) try: arg_names = inspect.signature( mark.args[0]).parameters.keys() # odict_keys except TypeError: logger.exception(log_msg) return not bool(mark.args[0]), reason app = find_appliance(item, require=False) if app: global_vars = {'appliance': app} else: logger.info("while uncollecting %s - appliance not known", item) global_vars = {} try: values = extract_fixtures_values(item) values.update(global_vars) # The test has already been uncollected if arg_names and not values: return True, None args = [values[arg] for arg in arg_names] except KeyError: missing_argnames = list( set(arg_names) - set(item._request.fixturenames)) func_name = item.name if missing_argnames: raise Exception( f'uncollectif lambda requesting fixture {missing_argnames} ' f'which is not in the test function {func_name} signature') else: raise Exception(f'uncollectif {func_name} hit KeyError, ' 'best guess a fixture was not ready') retval = mark.args[0](*args) if retval: # shortcut return retval, reason else: return False, None else: # no uncollect markers return False, None
def uncollectif(item): """ Evaluates if an item should be uncollected Tests markers against a supplied lambda from the markers object to determine if the item should be uncollected or not. """ from cfme.utils.appliance import find_appliance from cfme.utils.pytest_shortcuts import extract_fixtures_values markers = item.get_marker('uncollectif') if not markers: return False, None for mark in markers: log_msg = 'Trying uncollecting {}: {}'.format( item.name, mark.kwargs.get('reason', 'No reason given')) logger.debug(log_msg) try: arg_names = inspect.getargspec(get_uncollect_function(mark)).args except TypeError: logger.debug(log_msg) return not bool(mark.args[0]), mark.kwargs.get('reason', 'No reason given') app = find_appliance(item, require=False) if app: global_vars = {'appliance': app} else: logger.info("while uncollecting %s - appliance not known", item) global_vars = {} try: values = extract_fixtures_values(item) values.update(global_vars) # The test has already been uncollected if arg_names and not values: return True, None args = [values[arg] for arg in arg_names] except KeyError: missing_argnames = list(set(arg_names) - set(item._request.funcargnames)) func_name = item.name if missing_argnames: raise Exception("You asked for a fixture which wasn't in the function {} " "prototype {}".format(func_name, missing_argnames)) else: raise Exception("Failed to uncollect {}, best guess a fixture wasn't " "ready".format(func_name)) retval = mark.args[0](*args) if retval: # shortcut return retval, mark.kwargs.get('reason', "No reason given") else: return False, None else: return False, None
def get_testcase_data(tests, test_names, item, legacy=False): """Gets data for single testcase entry.""" legacy_name, parametrized_name = get_polarion_name(item) name = legacy_name if legacy else parametrized_name if name in test_names: return work_items = [] custom_fields = {} try: description = item.function.func_doc except Exception: description = "" try: requirement = item.get_marker('requirement').args[0] requirement_id = cfme_data['requirements'][requirement] work_items.append({'id': requirement_id, 'role': 'verifies'}) except Exception: pass try: tier = item.get_marker('tier').args[0] tier_id = caselevels[str(tier)] custom_fields['caselevel'] = tier_id except Exception: pass param_list = extract_fixtures_values(item).keys() if not legacy else None manual = item.get_marker('manual') if not manual: # The master here should probably link the latest "commit" eventually automation_script = 'http://github.com/{0}/{1}/blob/master/{2}#L{3}'.format( xunit['gh_owner'], xunit['gh_repo'], item.location[0], item.function.func_code.co_firstlineno ) custom_fields['caseautomation'] = "automated" custom_fields['automation_script'] = automation_script # Description with timestamp and link to test case source. # The timestamp will not be visible in Polarion, but will cause Polarion # to update the "Updated" field even when there's no other change. description = '{0}<br id="{1}"/><br/><a href="{2}">Test Source</a>'.format( description, timestamp, automation_script) else: custom_fields['caseautomation'] = "manualonly" description = '{}'.format(description) test_names.append(name) tests.append(dict( test_name=name, description=description, parameters=param_list, linked_items=work_items, custom_fields=custom_fields))
def skip_plugin(item, skip, reason="Skipped"): if isinstance(skip, bool): if skip: pytest.skip(reason) elif callable(skip): skip_kwargified = kwargify(skip) if skip_kwargified(**extract_fixtures_values(item)): pytest.skip(reason) else: if bool(skip): pytest.skip(reason)
def uncollectif(item): """ Evaluates if an item should be uncollected Tests markers against a supplied lambda from the marker object to determine if the item should be uncollected or not. """ from cfme.utils.pytest_shortcuts import extract_fixtures_values marker = item.get_marker('uncollectif') if marker: from cfme.utils.log import logger log_msg = 'Trying uncollecting {}: {}'.format( item.name, marker.kwargs.get('reason', 'No reason given')) try: arg_names = inspect.getargspec(get_uncollect_function(marker)).args except TypeError: logger.debug(log_msg) return not bool(marker.args[0]) try: values = extract_fixtures_values(item) # The test has already been uncollected if arg_names and not values: return args = [values[arg] for arg in arg_names] except KeyError: missing_argnames = list( set(arg_names) - set(item._request.funcargnames)) func_name = item.name if missing_argnames: raise Exception( "You asked for a fixture which wasn't in the function {} " "prototype {}".format(func_name, missing_argnames)) else: raise Exception( "Failed to uncollect {}, best guess a fixture wasn't " "ready".format(func_name)) retval = marker.args[0](*args) if retval: logger.debug(log_msg) return not retval else: return True
def uncollectif(item): """ Evaluates if an item should be uncollected Tests markers against a supplied lambda from the marker object to determine if the item should be uncollected or not. """ from cfme.utils.pytest_shortcuts import extract_fixtures_values marker = item.get_marker('uncollectif') if marker: from cfme.utils.log import logger log_msg = 'Trying uncollecting {}: {}'.format( item.name, marker.kwargs.get('reason', 'No reason given')) try: arg_names = inspect.getargspec(get_uncollect_function(marker)).args except TypeError: logger.debug(log_msg) return not bool(marker.args[0]) try: values = extract_fixtures_values(item) # The test has already been uncollected if arg_names and not values: return args = [values[arg] for arg in arg_names] except KeyError: missing_argnames = list(set(arg_names) - set(item._request.funcargnames)) func_name = item.name if missing_argnames: raise Exception("You asked for a fixture which wasn't in the function {} " "prototype {}".format(func_name, missing_argnames)) else: raise Exception("Failed to uncollect {}, best guess a fixture wasn't " "ready".format(func_name)) retval = marker.args[0](*args) if retval: logger.debug(log_msg) return not retval else: return True