How to exclude mock package from python coverage report using nosetests

前端 未结 3 1930
南笙
南笙 2020-12-25 11:39

I currently try to use the mock library to write some basic nose unittests in python.

After finishing some basic example I now tried to use nosetests --with-co

相关标签:
3条回答
  • 2020-12-25 11:52

    Create a .coveragerc file that excludes what you don't want in the report: http://nedbatchelder.com/code/coverage/config.html

    0 讨论(0)
  • 2020-12-25 12:05

    In your .coveragerc move your omit entry from the [report] section to the [run] section.

    0 讨论(0)
  • 2020-12-25 12:05

    I had a similar situation testing a series of sub-packages within my main package directory. I was running nosetests from within the top directory of my module and Mock and other libraries were included in the coverage report. I tried using --cover-module my_package in nosetests, but then the subpackages were not included.

    Running the following solved my problem:

    nosetests --with-coverage --cover-erase --cover-package ../my_package
    

    So, if all the code that you want to test is in the same directory, then you can get coverage for it alone by specifying the module path to nosetests. This avoids the need to whitelist each of the submodules individually.

    (Python 2.7.6, coverage 4.0.3, nose 1.3.7)

    0 讨论(0)
提交回复
热议问题