def directory_arg(path: str, optname: str) -> str:
    """Argparse type validator for directory arguments.

    :path: Path of directory.
    :optname: Name of the option.
    """
    if not os.path.isdir(path):
        raise UsageError(f"{optname} must be a directory, given: {path}")
    return path
Argparse type validator for directory arguments.

    :path: Path of directory.
    :optname: Name of the option.
    
src/_pytest/config/__init__.py