pytest lastfailed原理

相信很多使用pytest的,都知道pytest有运行上次失败用例的参数,如下:

1
2
3
4
--lf, --last-failed   rerun only the tests that failed at the last run (or all if none failed)
  --ff, --failed-first  run all tests, but run the last failures first.
                        This may re-order tests and thus lead to repeated fixture setup/teardown.
  --nf, --new-first     run tests from new files first, then the rest of the tests sorted by file mtime

  但实际原理是什么呢?

我们还是来看看官方的说明:

 

1
plugins may access the config.cache object to set/get json encodable values between pytest invocations.

  

这说明会生成一个cache文件,这个文件在我们执行时会说明,如下:

 用这里可以看出,这是一个隐藏文件,所以我们在pycharm中看不到。打开文件夹可以看到

再继续下去,有这样一个文件:.pytest_cache\v\cache\lastfailed

我们打开,是不是发现原来所有错误的用例都放在这里。

我们也可以通过以下几种方式验证:

仅仅收集不执行错误用例
pytest --lf --co
查看cache里的内容
pytest --cache-show
清空cache
pytest --cache-clear

 

posted @   Believer007  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
历史上的今天:
2016-04-28 python requests模块中返回时间elapsed解析

喜欢请打赏

扫描二维码打赏

了解更多

点击右上角即可分享
微信分享提示