def find_testdir(number, dir):
    """Find the configuration directory for a test based on its
    number. The given directory must contain exactly one directory
    with a name matching "NUMBER_*", otherwise a LookupError is
    raised.

    """
    found = None
    for entry in dir.iterdir():
        if entry.is_dir():
            num = int(entry.name.split('_', maxsplit=1)[0])
            if number == num:
                if found:
                    # duplicate numbers are an error
                    raise LookupError('Multiple directories found for '
                                      f'test number {number}: '
                                      f'{found.name} and {entry.name}')
                else:
                    found = entry
    if found is None:
        raise LookupError('No test directory found for test number '
                          f'{number}!')
    return found, found.name