import unittest
import fnmatch


def find_test(entity, pattern):
    """
    search for a unit test with a matching wildcard pattern

    Looks for the first 'unittest.case.TestCase' instance where its identifier
    matches the provided wildcard pattern.
    """
    if isinstance(entity, unittest.case.TestCase):
        if fnmatch.fnmatch(entity.id(), '*{}*'.format(pattern)):
            return entity
    elif isinstance(entity, unittest.TestSuite):
        for subentity in entity:
            found = find_test(subentity, pattern)
            if found:
                return found

    return None