Skip to main content

A Pytest plugin for your Cookiecutter templates

Project description

Join the chat at https://gitter.im/hackebrot/pytest-cookies PyPI Package Documentation Status See Build Status on Travis CI See Build Status on AppVeyor

pytest is a mature full-featured Python testing tool that provides easy no boilerplate testing. Its hook-based customization system supports integration of external plugins such as pytest-cookies.

This plugin 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.

https://raw.github.com/audreyr/cookiecutter/aa309b73bdc974788ba265d843a65bb94c2e608e/cookiecutter_medium.png

Installation

pytest-cookies is available for download from PyPI via pip:

$ pip install pytest-cookies

It will automatically install pytest along with cookiecutter.

Usage

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.basename == 'helloworld'
    assert result.project.isdir()

It accepts the extra_context keyword argument that will be passed to cookiecutter. The given dictionary will override the default values of the template context, allowing you to test arbitrary user input data.

Please see the Injecting Extra Context section of the official cookiecutter documentation.

Features

cookies.bake() returns a result instance with a bunch of fields that hold useful information:

  • exit_code: is the exit code of cookiecutter, 0 means successful termination

  • exception: is the exception that happened if one did

  • project: a py.path.local object pointing to the rendered project

The returned LocalPath instance provides you with a powerful interface to filesystem related information, that comes in handy for validating the generated project layout and even file contents:

def test_readme(cookies):
    result = cookies.bake()

    readme_file = result.project.join('README.rst')
    readme_lines = readme_file.readlines(cr=False)
    assert readme_lines == ['helloworld', '==========']

Issues

If you encounter any problems, please file an issue along with a detailed description.

Contributing

Contributions are very welcome! Tests can be run with tox, please make sure all of the tests are green before you submit a pull request.

Code of Conduct

Everyone interacting in the Pytest-Cookies project’s codebase, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.

License

Distributed under the terms of the MIT license, Pytest-Cookies is free and open source software

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-cookies-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_cookies-0.1.0-py2.py3-none-any.whl (7.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-cookies-0.1.0.tar.gz.

File metadata

File hashes

Hashes for pytest-cookies-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c7779103286dfefafea1881f875a799682d1a15d1fa3cacf103dbc241b97d0a
MD5 69addadc0c0dcfabe610aff399b63bc9
BLAKE2b-256 d4445c0518e89133287bf5a162e76d8d92d1f68dfcbc62acd7989407a908d114

See more details on using hashes here.

File details

Details for the file pytest_cookies-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_cookies-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d8b8d8a6aae54517983937b8c6bf557585a9ef5be4af063ef2bdfce522c17691
MD5 78d6b20ff9b84a482f6271d1fe6c9c6c
BLAKE2b-256 b9bdcff2343bb99e3368a41a61250f1836dd6d86b821e0e8eceddfd8eede915f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page