pytest lastfailed原理

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

--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

  但实际原理是什么呢?

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

 

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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章