12rambau / pytest-copie

The pytest plugin for your copier templates 📒
https://pytest-copie.readthedocs.io/en/latest/
MIT License
14 stars 2 forks source link

Usage docs page example does not work correctly #48

Closed GenevieveBuckley closed 8 months ago

GenevieveBuckley commented 9 months ago

Describe the bug The example demo from the Usage docs page does not work. Multiple errors are produced.

To Reproduce Steps to reproduce the behavior:

  1. Create a new test environment, with python 3.10, pip, copier, pytest, and pytest-copie.
  2. Go to the Usage docs page
  3. Create this repository structure:
    my_template/
    ├── {{repo_name}}/
    │   └── README.rst.jinja
    ├── tests/
    │   └── test_template.py
    └── copier.yaml
  4. Add this content to the file copier.yaml
    repo_name:
    type: str
    default: foobar
    short_description:
    type: str
    default: Test Project
  5. Add this content to the file README.rst.jinja:
    
    {{ repo_name }}
    ===============

{{ short_description }}

5. Add this content to the file ``:
```python
def test_template(copie):
    result = copie.copy()

    assert v.exit_code == 0
    assert result.exception is None
    assert result.project_dir.name == "foobar"
    assert result.project_dir.is_dir()
  1. Confirm that regular old copier works on this example repo: cd ..; copier copy my_template my_output. Observe that it works, and has created a "foobar" directory containing a README.rst file containing a "foobar" heading and the example short description.
  2. Try running pytest (with pytest-copie on the my_template repository: cd my_template; pytest --keep-copied-projects --pdb
  3. See the pytest errors

Additional context There were a number of errors. I've found and made fixes for some easy ones, but am still not quite sure about some others.

GenevieveBuckley commented 9 months ago

Questions:

  1. Should we use the workaround I suggested here, or do you know how to make the yaml work so we can use _subdirectory: {{repo_name}} directly?

A workaround that helped was to restructure the repository, so we had my_template/template/{{repo_name}}/README.rst.jinja, and in copier.yaml I wrote _subdirectory: template.

  1. How should I convince pytest-copie to look in the right place for the project_dir folder?

I found this line, so I think if I mess around with the extra_answers dictionary values, I might be able to do it https://github.com/12rambau/pytest-copie/blob/bd114eb5202933165f68e0ad98eb8d6ae6e06386/pytest_copie/plugin.py#L62