Running tests from coverage.py vs running coverage from test runner

寵の児 提交于 2019-12-21 05:52:32

问题


During the Coverage.py with Ned Batchelder python&testing podcast, Brian and Ned briefly discussed that, if you need to run tests with coverage, it is preferred to run tests from coverage.py executing the coverage run as opposed to invoking a test runner with coverage. Why is that and what is the difference?


To put some context into this: currently I'm using nose test runner and execute the tests with the help of nosetests command-line tool with --with-coverage option:

$ nosetests --with-coverage --cover-html

Should I do it via the coverage run -m instead?

$ coverage run -m nose
$ coverage report

回答1:


I guess I am uniquely qualified to answer this question :)

mwchase and mgilson have it right in their comments: using a plugin means you are depending on that plugin's behavior being correct and understandable. In the name of being helpful, plugins will have their own logic that may have been the best idea when they were written, but the test runner and/or coverage.py may have changed in the meantime. The plugins tend not to be as well-maintained as the other components. If you can avoid them, you have one less thing to think about.

True fact: the reason I added support for .coveragerc configuration files in the first place was because I wanted to add features to coverage.py and didn't want to wait for plugin UIs to be updated to support them.



来源:https://stackoverflow.com/questions/38237057/running-tests-from-coverage-py-vs-running-coverage-from-test-runner

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