Is it possible exclude test directories from coverage.py reports?

和自甴很熟 提交于 2019-12-03 11:27:26

问题


I'm kind of a rookie with python unit testing, and particularly coverage.py. Is it desirable to have coverage reports include the coverage of your actual test files?

Here's a screenshot of my HTML report as an example.

You can see that the report includes tests/test_credit_card. At first I was trying to omit the tests/ directory from the reports, like so:

coverage html --omit=tests/ -d tests/coverage

I tried several variations of that command but I could not for the life of me get the tests/ excluded. After accepting defeat, I began to wonder if maybe the test files are supposed to be included in the report.

Can anyone shed some light on this?


回答1:


coverage html --omit="*/test*" -d tests/coverage




回答2:


Create .coveragerc file in your project root folder, and include the following:

[run]
omit = *tests*



回答3:


You can also explicitly specify which directory has the code you want coverage on instead of saying which things to omit. In a .coveragerc file, if the directory of interest is called demo, this looks like

[run]
source = demo


来源:https://stackoverflow.com/questions/1628996/is-it-possible-exclude-test-directories-from-coverage-py-reports

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