Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to use copier instead of cookiecutter #13

Merged
merged 4 commits into from
Jul 19, 2024

Conversation

sjvrijn
Copy link
Contributor

@sjvrijn sjvrijn commented Jul 16, 2024

Summary

Updates all tests to remove references to cookiecutter or the pytest-cookies plugin, and makes sure all tests work with copier instead. Note that the tests in test_values only tests for not erroring, and the 'directory name with spaces' test now expects an error since that validation is not (yet) implemented for copier.

Fixes #1 (?)

Instructions to review the pull request

Add my fork as a remote and switch to the 1-update-tests branch (or make a new clone, your choice), then install the required dependencies and run the tests.

Note: On my local WSL installation, the tox test hangs for some reason, although I suspect this may be a pyenv related issue. I'm assuming/hoping that this will not be a problem in the CI.

git remote add sjvrijn git@github.com:sjvrijn/copier-python-template.git
git fetch sjvrijn
git switch 1-update-tests
python -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip setuptools
pip install ".[dev]"
pytest

@lyashevska lyashevska self-requested a review July 17, 2024 07:42
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we need to test values now, because validators e.g. this force user to provide correct input. Lets discuss this.

@@ -45,7 +45,7 @@ install_requires =
dev =
coverage [toml]
pytest
pytest-cookies
pyprojroot
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar with pyprojroot. I was originally thinking of replacing 'pytest-cookies' with 'pytest-copie'. See https://github.com/12rambau/pytest-copie

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyprojroot is a simple but very helpful package to easily refer to paths relative to the project root. For the tests specifically, I used it to guarantee that the source refers to the root of the project, regardless of where the tests are called from (which can sometimes cause issues with these things.)

Using pytest-copie would be nice, but it doesn't a session-scoped fixture such as the one that pytest-cookies does. That means we end up with a whole bunch of ScopeMismatch errors if we do a 'naive' replacement:

ERROR tests/test_project.py::test_pytest - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_coverage - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_tox - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_subpackage - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_generate_api_docs - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_coverage_api_docs - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_doctest_api_docs - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_ruff_check - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:
ERROR tests/test_project.py::test_bumpversion - Failed: ScopeMismatch: You tried to access the function scoped fixture copie with a session scoped request object. Requesting fixture stack:

Looking at the pytest-cookies code, it seems like it should be an easy contribution to add a similar session scoped version. We should look into that!

@lyashevska
Copy link
Owner

Great work @sjvrijn! Thanks. I have left a few inline comments for us to discuss. I have tested it on my machine and one test has failed...
FAILED tests/test_project.py::test_coverage_api_docs - AssertionError: assert '| my_python_package | 100.00% | 0 |' in ['Undocumente... =1 failed, 13 passed, 2 warnings in 63.52s (0:01:03)

This adapts the custom session scoped fixture to manually create a
copier copy, since the pytest-copie plugin does not yet support a
session-scoped fixture
Copy link
Owner

@lyashevska lyashevska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks great Sander! I will merge it now.

@lyashevska lyashevska merged commit 4016ac6 into lyashevska:main Jul 19, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix CI tests
2 participants