def _find_matching_node(parent, request):
    """Try to find a matching child node based on a test request.

    Node search order is as follows:
    - Node matching the exact test name
    - Node matching the class name + test name (minus 'test_' prefix for function name)
    - Node matching the class name

    """
    test_name = request.node.name

    # First try to find a node with the exact test name.
    names = [test_name]

    if request.cls is not None:
        cls_name = request.cls.__name__.lower()

        test_name = test_name[5:]

        # Look for a node with the class name + test name (minus test_ from function name)
        names.append("{}_{}".format(cls_name, test_name))

        # Finally try to find a node with the class name.
        names.append(cls_name)

    node = None

    for name in names:
        node = parent.node(name)

        if node is not None:
            break

    return node