def get_item_by_id(test_item, item_id):
    """Return the requested test item by its identifier.

    Goes over the test item's sub tests recursively and returns
    the one that matches the requested identifier.
    The search algorithm assumes that the identifiers assignment was the
    default one (use of default indexer), which identifies the tests in a DFS
    recursion.
    The algorithm continues the search in the sub-branch which root has the
    highest identifier that is still smaller or equal to the searched
    identifier.

    Args:
        test_item (object): test instance object.
        item_id (number): requested test identifier.

    Returns:
        TestCase / TestSuite. test item object.
    """
    if test_item.identifier == item_id:
        return test_item

    if test_item.IS_COMPLEX:
        sub_test = max([sub_test for sub_test in test_item
                        if sub_test.identifier <= item_id],
                       key=lambda test: test.identifier)

        return get_item_by_id(sub_test, item_id)