一个与pytest一起使用的简单插件

pytest-diff的Python项目详细描述


PyPI versionPython versionsSee Build Status on Travis CISee Build Status on AppVeyor

一个与pytest一起使用的简单插件


这个pytest插件是用Cookiecutter@hackebrotcookiecutter-pytest-plugin模板生成的。

功能

  • 失败测试的可读差异
  • 为您的课程定制差异

要求

  • pytest
  • 深度差异
  • pprintpp

安装

您可以通过pipPyPI

$ pip install pytest-diff

用法

classPerson:def__init__(self,name,age,favorites):self.name=nameself.age=ageself.favorites=favoritesdeftest_person():a=Person("Alice",age=21,favorites={"food":"spam","movie":"Life of Brian"})b=Person("Alice",age=21,favorites={"food":"eggs","movie":"Life of Brian"})asserta==b

运行pytest给出:

______________________________test_person______________________________deftest_person():a=Person("Alice",age=21,favorites={'food':'spam','movie':'Life of Brian'})b=Person("Alice",age=21,favorites={'food':'eggs','movie':'Life of Brian'})>asserta==bEassertE<test_person.Personobjectat0x7fa326d769e8>E==E<test_person.Personobjectat0x7fa326d76be0>E{'values_changed':{"root.favorites['food']":{'new_value':'spam','old_value':'eggs'}}}examples/test_person.py:11:AssertionError

要为特定类型自定义diff,请在注册表中注册:

importpytest_diffclassCar:def__init__(self,make,model,year):self.make=makeself.model=modelself.year=year@pytest_diff.registry.register(Car)defdiff(x,y):return[f"{x.make} vs {y.make}",f"{x.model} vs {y.model}",f"{x.year} vs {y.year}",]deftest_car():c1=Car("Toyota","Prius",2010)c2=Car("Honda","Accord",2009)assertc1==c2

然后运行pytest显示您的自定义差异:

deftest_car():c1=Car("Toyota","Prius",2010)c2=Car("Honda","Accord",2009)>assertc1==c2EassertE<test_custom.Carobjectat0x7f0e9b0ccd68>E==E<test_custom.Carobjectat0x7f0e9b0cceb8>EToyotavsHondaEPriusvsAccordE2010vs2009examples/test_custom.py:21:AssertionError

贡献

我们非常欢迎您的贡献。测试可以用tox运行,请确保 在提交请求之前,覆盖范围至少保持不变。

许可证

“pytest diff”是根据MIT许可证的条款发布的免费开源软件

问题

如果您遇到任何问题,请file an issue连同详细说明。

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

推荐PyPI第三方库


热门话题
java根据两个数组的值对数组进行排序   具有自签名证书和NTLM代理的java Maven SSL repo错误   java自定义字体按钮不工作AndroidStudio   java通过Spring MVC web应用程序向客户端发送文本文件   Java Spring Web服务SOAP身份验证   ANT property environment=“env”无法在JAVA中检索它,但如果作为ANT命令运行,则可以正常工作   java是为spring mvc rest api或spring boot api对应用服务器的每个新请求创建的服务、存储库和组件的新实例吗?   java私有静态最终字符串未完成其工作   PKCS12的安全Java密钥重新处理   java JPA继承表每类SQLSyntaxErrorException