python 代碼覆蓋率 coverage用法


 

 

先裝coverage:


D:\test_python\e8_test>pip install coverage
Collecting coverage
  Downloading https://files.pythonhosted.org/packages/42/60/e6958685ab99e7b54dc5f2dddf85f648a4577bc1ca85b8e80ce8474f6e23/coverage-4.5.1-cp27-cp27m-win32.whl (178kB)
    100% |################################| 184kB 233kB/s
Installing collected packages: coverage
Successfully installed coverage-4.5.1

代碼:

#coding=utf-8
import unittest

if __name__ == '__main__' :
  
    testSuite = unittest.TestLoader().discover('.')
    unittest.TextTestRunner(verbosity = 2).run(testSuite)

運行coverage run task_test.py

D:\test_python\e8_test>coverage run task_test.py
10
-8
24
2
-1
-1
24
2

輸出報告:coverage report -m

D:\test_python\e8_test>coverage report -m
Name           Stmts   Miss  Cover   Missing
--------------------------------------------
task_test.py      35      0   100%

 

輸出html報告coverage html

D:\test_python\e8_test>coverage html

 

文件可以在當前目錄下的htmlcov下找到

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM