Show the differences in two test-coverage runs

北慕城南 提交于 2020-02-08 10:14:31

问题


I'm in the process of writing tests for some old and disowned code. I've found coverage.py to be a useful tool in helping me decide which test to write next. As I improve our testing I'd like to see how I've affected our coverage.

Currently I'm doing this by bringing up the html report twice, in side-by-side browser windows, and visually looking for differences. This seems very crude. Do any of you have a better solution?

I found z3c.coverage, and after struggling to get zope-testrunner working with our tests, found that it only reports on regressions, not improvements. I could give the inputs as reverse, so that improvements look like regressions, but that will be quite confusing to present to others.


回答1:


Coverage.py doesn't have a diff feature. Sounds cool though, want to provide a patch? :)




回答2:


I was in similar situation. I wanted to see if the coverage has dropped. There was no straight forward way to get it. so, I wrote some python script and a shell script. I works fine, I have it jenkins now.

Steps

  1. Store previous report and current report (something report.prev and report.curr)

report text format:(this is default format and found it easy to parse)

Name                                     Stmts   Miss  Cover
------------------------------------------------------------------------------
my/project/example.py                     3      3     0%
  1. parse report into maps where key, value is { filename : coverage_percentage }

    example:

previous_run = { 
    '/my/filename.py' : '67', 
    '/one/more/file.py' : '89'
}

current_run = {
    '/my/filename.py' : '67',
    '/one/more/file.py' : '89'
}
  1. Then we can compare these maps (current_run, previous_run)

  2. On new report generation, roll the files: Meaning, move current report file to previous ('mv report.curr report.prev') and new file to report.curr

I have put full implementation here: https://github.com/diganthdr/handytools See (coverage_compare.py)



来源:https://stackoverflow.com/questions/15208925/show-the-differences-in-two-test-coverage-runs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!