coveralls.io 跑 python project 的覆蓋率就是用 coverage.py
nose 也是用 coverage.py
基本上 Python 社群幾乎都是用這個
ref:
http://nedbatchelder.com/code/coverage/
http://www.cnblogs.com/coderzh/archive/2009/12/01/1614874.html
Install
$ pip install coverage
Configuration
in .coveragerc
[run]
branch = True
source = email_confirm_la
omit =
email_confirm_la/migrations/*
email_confirm_la/south_migrations/*
email_confirm_la/tests/*
[run] 底下的 include 和 omit 是用來指定 filename pattern
而 source 是用來指定 package 或目錄
omit 是「忽略」的意思
ref:
http://nedbatchelder.com/code/coverage/config.html
Usage
# 會自動套用當前目錄下的 .coveragerc
$ coverage run setup.py test
$ coverage report
$ coverage html
# 默認會一併測試所有包含第三方 lib 在內的 Python 程式碼(如果你沒有寫 .coveragerc 的話)
$ coverage run test.py
# 你可以用 --source 指定只測試某個 packages 或目錄
$ coverage run --source=haul setup.py test
$ coverage run --source=haul tests/test.py
$ coverage run --source=. manage.py test
# show report in terminal
$ coverage report
# generate html report in the same dir
$ coverage html
ref:
http://nedbatchelder.com/code/coverage/cmd.html
http://nedbatchelder.com/code/coverage/source.html
Usage with nose
$ pip install nose nose-cov
# output terminal
$ nosetests --with-cov --cov haul tests/
# output html
$ nosetests --with-cov --cov-report html --cov haul tests/