pytest的hook函数使用总结

本文详细介绍了pytest的hook函数,包括pytest_collectreport、pytest_report_collectionfinish、pytest_runtestloop,以及pytest_addoption和pytest_configure。这些函数分别在测试模块收集、全部测试项收集结束、测试执行循环、命令行参数添加和配置初始化时被调用。通过实例展示了如何使用这些hook函数,以及在conftest.py文件中添加和注册插件的方法。
摘要由CSDN通过智能技术生成

1.pytest_collectreport(report)

这个函数在每个模块收集器收集结束后调用

report是_pytest的runner.py模块 CollectReport 的实例

 

CollectReport定义如下

class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result,
      sections=(), **extra):
      self.nodeid = nodeid #模块::测试class
      self.outcome = outcome  #nodeid扫描结果
      self.longrepr = longrepr 
      self.result = result or [] #TestCaseFunction或者UnitTestCase的list
      self.sections = list(sections)
      self.__dict__.update(extra)

@property
def location(self):
     return (self.fspath, None, self.fspath) #fspath,模块的完整文件路径

def __repr__(self):
     return "<CollectReport %r lenresult=%s outcome=%r>" % (
              self.nodeid, len(self.result), self.outcome)

 

 

2.pytest_report_collectionfinish(config, startdir, it

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值