pytest-cookies
raw JSON → 0.7.0 verified Fri May 01 auth: no python
A pytest plugin for testing Cookiecutter templates. It provides a `cookies` fixture that wraps the Cookiecutter API for generating projects, making it easy to verify templates work as expected. Current version 0.7.0 supports Python >=3.7 and Cookiecutter >=2.1.0. Releases are infrequent but stable.
pip install pytest-cookies Common errors
error ModuleNotFoundError: No module named 'pytest_cookies' ↓
cause pytest-cookies not installed or not importable as a standalone module.
fix
Install with pip install pytest-cookies and ensure the test file uses the 'cookies' fixture, not direct imports.
error AttributeError: 'Result' object has no attribute 'project' ↓
cause Using deprecated result.project which was removed in v0.6.0.
fix
Use result.project_path instead.
error TypeError: 'NoneType' object is not subscriptable (when accessing result.project_path) ↓
cause Template baking failed, result is None.
fix
Check that the template path exists and Cookiecutter is properly configured.
Warnings
deprecated Result.project is deprecated in v0.6.0. Use Result.project_path instead. ↓
fix Replace result.project with result.project_path (returns pathlib.Path).
breaking Cookiecutter 2.1.0 introduced breaking changes; pytest-cookies 0.7.0 is required for compatibility. ↓
fix Upgrade pytest-cookies to >=0.7.0.
gotcha By default, baked projects are deleted after the test. Use --keep-baked-projects CLI option to retain them. ↓
fix Run pytest with --keep-baked-projects flag to inspect generated files.
Imports
- Result wrong
from pytest_cookies import Resultcorrectfrom pytest_cookies.plugin import Cookies, Result
Quickstart
import os
def test_bake_project(cookies):
result = cookies.bake(extra_context={"repo_name": "helloworld"})
assert result.exit_code == 0
assert result.exception is None
assert result.project_path.name == "helloworld"
assert result.project_path.is_dir()