import fnmatch


def _expand_wildcard_method_list_items(base_class_methods, test_methods):
    """Updates any entries in a test/skip method list with wildcards

    Adds list entries for each test method that matches a wildcard entry, then
    removes all wildcard entries after expanding. Additionally, any duplicate
    entries in the list after wildcard expansion will be removed so the same
    test method isn't run multiple times

    :param base_class_methods: List of all test methods in the test case class
        (i.e. result of loader.getTestCaseNames())
    :param test_methods: List of test case method names (or wildcard strings)

    :return: The modified ``test_methods`` list or ``None`` if the updated list
        is empty (i.e. it was all wildcards and none of them matched any test
        methods)
    """
    # Get list of wildcard test methods
    wildcard_methods = [method for method in test_methods]
    # Temporary list of matching test methods used to update the original
    updated_test_methods = []
    for wildcard_method in wildcard_methods:
        matching_methods = fnmatch.filter(base_class_methods, wildcard_method)
        # Update temporary list with matching test methods
        updated_test_methods.extend(matching_methods)
        # Remove wildcard name from original list after finishing
        test_methods.remove(wildcard_method)
    # Update original list
    test_methods.extend(updated_test_methods)
    # Remove duplicate entries (convert from a list to a dict and back)
    test_methods = list(dict.fromkeys(test_methods))
    # If none of the wildcard entries matched any test methods and the updated list is empty, set it to None
    if not test_methods:
        test_methods = None
    return test_methods