Cookiecutter模板的Pytest插件

pytest-cookies的Python项目详细描述


pytest cookies

pytest是一个成熟的python测试框架 一个欣欣向荣、不断发展的志愿者社区。它使用简单的断言 语句和常规python比较。在pytest测试的核心 框架是一个强大的基于钩子的插件系统。

pytest cookies是一个pytest插件,带有cookiesfixture 它是用于生成 项目。它帮助您验证模板是否按预期工作,以及 在运行测试后进行清理。

安装

pytest cookies可从PyPI通过pip下载:

pip install pytest-cookies

这将自动安装pytestcookiecutter

用法

生成新项目

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()在 当前目录。可以在命令行上通过传递 --templatepytest的参数:

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 cookiesContributor Code of Conduct一起发布。通过参与本项目,您同意 遵守其条款。

许可证

根据MIT licensepytest cookies的条款分发 是免费的开源软件。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用户界面如何在JavaGUI中为按钮创建各种颜色?   使用MSCAPI的RSA密钥包装的java使用   java Spring数据Redis JedisConnectionException:意外的流结束   java饼图未显示预期输出   java hystrixCommand注释commandKey的用途是什么   windows java可以从cmd运行jar,但不能通过双击来运行   java在单击按钮时遍历XML节点   java试图使用日期(int,int,int)构造函数   带有Buildship 2子项目的java不作为项目依赖项链接   java jsonrpc4j:如何从服务器获取列表<SomeObject>?   用于Java应用程序的内存设置MaxDirectMemory和MaxHeapMemory   java如何从以下类型格式化日期   javayoutube。搜索列表搜索不返回任何内容   java My参数在方法中不起作用,因为泛型存在问题   java如何将Map<Key1Type,Val1Type>转换为Map<Key1Type,Val2Type>   JavaJUnit测试:测试用例的改进,测试数组列表的长度?   java如何在Android中解析带有属性值的xml数据?   使用Hibernate对枚举类型进行Java8bean验证