def test_raise_undefined_variable_dir_name_existing_project(
    output_dir, undefined_context
) -> None:
    """Verify correct error raised when directory name cannot be rendered."""
    testproj_path = Path(output_dir, 'testproject')
    testproj_path.mkdir()

    with pytest.raises(exceptions.UndefinedVariableInTemplate) as err:
        generate.generate_files(
            repo_dir='tests/undefined-variable/dir-name/',
            output_dir=output_dir,
            context=undefined_context,
            overwrite_if_exists=True,
        )
    error = err.value

    directory = Path('testproject', '{{cookiecutter.foobar}}')
    msg = f"Unable to create directory '{directory}'"
    assert msg == error.message

    assert error.context == undefined_context

    assert testproj_path.exists()
Verify correct error raised when directory name cannot be rendered.
tests/test_generate_files.py