def test_echo_undefined_variable_error(output_dir, cli_runner) -> None:
    """Cli invocation return error if variable undefined in template."""
    template_path = 'tests/undefined-variable/file-name/'

    result = cli_runner(
        '--no-input',
        '--default-config',
        '--output-dir',
        output_dir,
        template_path,
    )

    assert result.exit_code == 1

    error = "Unable to create file '{{cookiecutter.foobar}}'"
    assert error in result.output

    message = (
        "Error message: 'collections.OrderedDict object' has no attribute 'foobar'"
    )
    assert message in result.output

    context = {
        '_cookiecutter': {
            'github_username': 'hackebrot',
            'project_slug': 'testproject',
        },
        'cookiecutter': {
            'github_username': 'hackebrot',
            'project_slug': 'testproject',
            '_template': template_path,
            '_repo_dir': template_path,
            '_output_dir': output_dir,
            '_checkout': None,
        },
    }
    context_str = json.dumps(context, indent=4, sort_keys=True)
    assert context_str in result.output
Cli invocation return error if variable undefined in template.
tests/test_cli.py