-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Describe the Bug
The test in tests/test_package_generation.py::test_pip_installable
python-tooling/tests/test_package_generation.py
Lines 95 to 123 in a3003e2
| 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