Registry / testing / pytest-cookies

pytest-cookies

JSON →
library0.7.0pypypi✓ verified 86d ago

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
INSTALL
IMPORT
SIG · PYTEST-COOKIES
P
pytest-cookies
testingpythonv0.7.0
Install
4.8s avg
Import
1174ms
Disk
47MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.238s · 46.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.8s · import 1.110s · 48MB
47MB installed
● package 47MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Result
from pytest_cookies.plugin import Cookies, Result
from pytest_cookies import Result
In v0.7.0, Result is in the plugin submodule; importing directly from pytest_cookies may fail.

Basic test for a Cookiecutter template using the cookies fixture.

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()
Debug
Known issues
deprecatedResult.project is deprecated in v0.6.0. Use Result.project_path instead.
fix
Replace result.project with result.project_path (returns pathlib.Path).
affects: >=0.6.0
breakingCookiecutter 2.1.0 introduced breaking changes; pytest-cookies 0.7.0 is required for compatibility.
fix
Upgrade pytest-cookies to >=0.7.0.
affects: <=0.6.1 with Cookiecutter >=2.1.0
gotchaBy 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.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pytest_cookies'
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.
AttributeError: 'Result' object has no attribute 'project'
Using deprecated result.project which was removed in v0.6.0.
fix
Use result.project_path instead.
TypeError: 'NoneType' object is not subscriptable (when accessing result.project_path)
Template baking failed, result is None.
fix
Check that the template path exists and Cookiecutter is properly configured.
Upgrade
Version history
0.7.0latest on PyPI · released Mar 22, 2023
Audit
Dependencies
pytestrequiredRequired plugin host.
cookiecutterrequiredCore dependency for template generation.
Agent activity
8 hits · last 30 days
node
6
Resources
pytest-cookies — pip install pytest-cookies · libregistry