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

test_pip_installable test make persistent changes to environment test is run in #516

Open
matt-graham opened this issue Feb 10, 2025 · 0 comments · May be fixed by #519
Open

test_pip_installable test make persistent changes to environment test is run in #516

matt-graham opened this issue Feb 10, 2025 · 0 comments · May be fixed by #519
Labels
bug Something isn't working

Comments

@matt-graham
Copy link
Collaborator

Describe the Bug

The test in tests/test_package_generation.py::test_pip_installable

def test_pip_installable(
tmp_path: pathlib.Path,
generate_package: typing.Callable,
) -> None:
"""Test generated package is pip installable."""
test_config = {
"github_owner": "test-user",
"project_short_description": "description",
"project_name": "Cookiecutter Test",
}
generate_package(config=test_config, path=tmp_path)
# Check project directory exists
test_project_dir = tmp_path / "cookiecutter-test"
pipinstall = subprocess.run( # noqa: S603
[ # noqa: S607
"python",
"-m",
"pip",
"install",
"-e",
test_project_dir,
],
capture_output=True,
check=False,
)
assert pipinstall.returncode == 0, (
f"Something went wrong with installation: {pipinstall.stderr!r}"
)

installs an instance of the template with the package name cookiecutter-test in the Python environment the test is run in, and this installation is not removed after test completion (successful or not).

While the actual generated package directory is created in a temporary directory that is cleared, the references to this package in the environment site-packages directory are not cleaned up.

I think we probably should create a virtual environment in a temporary directory and tests the package installation there. While we could just remove the package after checking installation, this has the downside that if we in future add any default dependencies to the package template then we would need to remember to also remove these.

To Reproduce

Create a clean virtual environment, install pytest. Run pip list to see initial installed package

Run

pytest tests/test_package_generation.py::test_pip_installable

from root of repository.

Run pip list again and compare to previous output.

Expected Behaviour

No persistent changes to environment are made by tests, in particular no hanging package installation references are left - specifically pip list output is same before and after running tests.

Actual Behaviour

pip list output changed after running tests - there will be an additional cookiecutter-test package listed pointing to a now non-existent temporary directory.

Version In Use

v1.0.0-31-ga3003e2

Additional Context

- Cookiecutter version: 2.6.0
- Operating system: Ubuntu
- Python version: 3.13.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant