Cookiecutter模板的Pytest插件
pytest-cookies的Python项目详细描述
pytest cookies
pytest是一个成熟的python测试框架 一个欣欣向荣、不断发展的志愿者社区。它使用简单的断言 语句和常规python比较。在pytest测试的核心 框架是一个强大的基于钩子的插件系统。
pytest cookies是一个pytest插件,带有cookies
fixture
它是用于生成
项目。它帮助您验证模板是否按预期工作,以及
在运行测试后进行清理。
安装
pip install pytest-cookies
这将自动安装pytest和 cookiecutter。
用法
生成新项目
cookies.bake()
方法从模板生成新项目
基于cookiecutter.json
:
deftest_bake_project(cookies):result=cookies.bake(extra_context={"repo_name":"helloworld"})assertresult.exit_code==0assertresult.exceptionisNoneassertresult.project.basename=="helloworld"assertresult.project.isdir()
cookies.bake()
方法还接受extra_context
关键字
将传递给Cookiecutter的论点。给定的词典将
重写模板上下文的默认值,有效地允许您
测试任意用户输入数据。
有关注入额外上下文的更多信息,请查看 cookiecutter documentation。
指定模板目录
默认情况下,cookies.bake()
在
当前目录。可以在命令行上通过传递
--template
pytest的参数:
pytest --template TEMPLATE
通过以下步骤,您可以从测试自定义cookiecutter模板目录
在可选的template
参数中:
@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.basename=="example-project"assertresult.project.isdir()
保留用于调试的输出目录
默认情况下cookies
删除烘焙的项目。
但是,如果您想保持 它们(it won't clutteras pytest只保留 三个最新的临时目录:
pytest --keep-baked-projects
社区
非常欢迎您的贡献!如果您遇到任何问题,请file an issue并附上详细说明。测试可以使用 tox。请确保所有测试都是绿色的,然后再提交 拉取请求。
你也可以自愿支持这个项目的发展 成为一名维护人员,这意味着您将能够对问题进行分类、合并 拉取请求并发布新版本。如果你感兴趣,请提交 请求将自己添加到maintainers和 我们会让你开始的!
请注意,pytest cookies随Contributor Code of Conduct一起发布。通过参与本项目,您同意 遵守其条款。
许可证
根据MIT license,pytest cookies的条款分发 是免费的开源软件。