The pytest plugin for your Cookiecutter templates. 🍪
Slowing down. Last release over 3 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install pytest-cookiespytest-cookies
pytest is a mature testing framework for Python that is developed by a thriving and ever-growing community of volunteers. It uses plain assert statements and regular Python comparisons. At the core of the pytest test framework is a powerful hook-based plugin system.
pytest-cookies is a pytest plugin that comes with a cookies fixture
which is a wrapper for the cookiecutter API for generating
projects. It helps you verify that your template is working as expected and
takes care of cleaning up after running the tests. 🍪
Installation
pytest-cookies is available for download from PyPI via pip:
pip install pytest-cookies
This will automatically install pytest and cookiecutter.
Usage
Generate a new project
The cookies.bake() method generates a new project from your template
based on the default values specified in cookiecutter.json:
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()
# The `project` attribute is deprecated
assert result.project.basename == "helloworld"
assert result.project.isdir()
Please note that the project attribute of the returned Result class is
deprecated and will be removed in a future release, please use project_path
instead.
The cookies.bake() method also accepts the extra_context keyword
argument that will be passed to cookiecutter. The given dictionary will
override the default values of the template context, effectively allowing you
to test arbitrary user input data.
For more information on injecting extra context, please check out the cookiecutter documentation.