def pytest_collection_modifyitems(items, config): """ called after collection has been performed, may filter or re-order the items in-place. Deselecting all tests skipped due to WONTFIX BZ. """ if not settings.configured: settings.configure() if settings.bugzilla.wontfix_lookup is not True: # if lookup is disable return all collection unmodified log('BZ deselect is disabled in settings') return items deselected_items = [] decorated_functions = group_by_key(pytest.bugzilla.decorated_functions) log("Collected %s test cases" % len(items)) for item in items: name = get_func_name(item.function, test_item=item) bug_ids = list(decorated_functions.get(name, [])) bug_ids.extend(_extract_setup_class_ids(item)) if any(bug_id in pytest.bugzilla.removal_ids for bug_id in bug_ids): deselected_items.append(item) log("Deselected test %s" % name) config.hook.pytest_deselected(items=deselected_items) items[:] = [item for item in items if item not in deselected_items]
def test_get_func_name(self): """Test if name is proper generated for function""" self.assertEqual( get_func_name(test_function), 'tests.robottelo.test_bz_helpers.test_function' )
def pytest_collection_modifyitems(items, config): """ called after collection has been performed, may filter or re-order the items in-place. Deselecting all tests skipped due to WONTFIX BZ. """ if not settings.configured: settings.configure() if settings.bugzilla.wontfix_lookup is not True: # if lookup is disable return all collection unmodified log('Deselect of WONTFIX BZs is disabled in settings') return items deselected_items = [] wontfix_ids = pytest.bugzilla.wontfix_ids decorated_functions = group_by_key(pytest.bugzilla.decorated_functions) log("Found WONTFIX in decorated tests %s" % wontfix_ids) log("Collected %s test cases" % len(items)) for item in items: name = get_func_name(item.function) bug_ids = decorated_functions.get(name) if bug_ids: for bug_id in bug_ids: if bug_id in wontfix_ids: deselected_items.append(item) log("Deselected test %s due to WONTFIX" % name) break config.hook.pytest_deselected(items=deselected_items) items[:] = [item for item in items if item not in deselected_items]
def test_get_func_name_with_class(self): """Test if name is proper generated for function with class name""" self.assertEqual( get_func_name(self.test_get_func_name_with_class), ('tests.robottelo.test_bz_helpers.BZHelperTestCase' '.test_get_func_name_with_class') )
def register_bug_id(self, func): # pragma: no cover """Every time the test is decorated, takes the BZ number and register it in pytest global namespace variable to be accessible in conftest in order to perform the filtering of test collection """ bz_namespace = getattr(pytest, 'bugzilla', None) if bz_namespace: bz_namespace.decorated_functions.append( (get_func_name(func), str(self.bug_id)))
def register_bug_id(self, func): # pragma: no cover """Every time the test is decorated, takes the BZ number and register it in pytest global namespace variable to be accessible in conftest in order to perform the filtering of test collection """ bz_namespace = getattr(pytest, 'bugzilla', None) if bz_namespace: bz_namespace.decorated_functions.append( (get_func_name(func), str(self.bug_id)) )