Package: pytest-cookies
pytest-cookiespytestis 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-cookiesis a pytest plugin that comes with acookiesfixture
which is a wrapper for thecookiecutterAPI for generating
projects. It helps you verify that your template is working as expected and
takes care of cleaning up after running the tests. 🍪Installationpytest-cookiesis available for download fromPyPIviapip:pip install pytest-cookiesThis will automatically installpytestandcookiecutter.UsageGenerate a new projectThecookies.bake()method generates a new project from your template
based on the default values specified incookiecutter.json:deftest_bake_project(cookies):result=cookies.bake(extra_context={"repo_name":"helloworld"})assertresult.exit_code==0assertresult.exceptionisNoneassertresult.project_path.name=="helloworld"assertresult.project_path.is_dir()# The `project` attribute is deprecatedassertresult.project.basename=="helloworld"assertresult.project.isdir()Please note that theprojectattribute of the returnedResultclass is
deprecated and will be removed in a future release, please useproject_pathinstead.Thecookies.bake()method also accepts theextra_contextkeyword
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 thecookiecutter documentation.Specify the template directoryBy defaultcookies.bake()looks for a cookiecutter template in the
current directory. This can be overridden on the command line by passing a--templateparameter to pytest:pytest --template TEMPLATEYou can customize the cookiecutter template directory from a test by passing
in the optionaltemplateparamter:@pytest.fixturedefcustom_template(tmpdir):template=tmpdir.ensure("cookiecutter-template",dir=True)template.join("cookiecutter.json").write('{"repo_name": "example-project"}')repo_dir=template.ensure("{{cookiecutter.repo_name}}",dir=True)repo_dir.join("README.rst").write("{{cookiecutter.repo_name}}")returntemplatedeftest_bake_custom_project(cookies,custom_template):"""Test for 'cookiecutter-template'."""result=cookies.bake(template=str(custom_template))assertresult.exit_code==0assertresult.exceptionisNoneassertresult.project_path.name=="example-project"assertresult.project_path.is_dir()Keep output directories for debuggingBy defaultcookiesremoves baked projects.However, you can pass thekeep-baked-projectsflag if you'd like to keep
them (it won't clutteras pytest only keeps the
three newest temporary directories):pytest --keep-baked-projectsCommunityContributions are very welcome! If you encounter any problems, pleasefile
an issuealong with a detailed description. Tests can be run withtox. Please make sure all of the tests are green before you submit a
pull request.You can also support the development of this project by volunteering to
become a maintainer, which means you will be able to triage issues, merge
pull-requests, and publish new releases. If you're interested, please submit
a pull-request to add yourself to the list ofmaintainersand
we'll get you started! 🍪Please note thatpytest-cookiesis released with aContributor Code of
Conduct. By participating in this project you agree to
abide by its terms.LicenseDistributed under the terms of theMIT license,pytest-cookiesis free and open source software.