zoukankan      html  css  js  c++  java
  • python 代码覆盖率 coverage用法

    先装coverage:


    D: est_pythone8_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: est_pythone8_test>coverage run task_test.py
    10
    -8
    24
    2
    -1
    -1
    24
    2

    输出报告:coverage report -m

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

    输出html报告coverage html

    D: est_pythone8_test>coverage html

    文件可以在当前目录下的htmlcov下找到

     

  • 相关阅读:
    台州 OJ 3847 Mowing the Lawn 线性DP 单调队列
    洛谷 OJ P1417 烹调方案 01背包
    快速幂取模
    台州 OJ 2649 More is better 并查集
    UVa 1640
    UVa 11971
    UVa 10900
    UVa 11346
    UVa 10288
    UVa 1639
  • 原文地址:https://www.cnblogs.com/xiaxiaoxu/p/9144551.html
Copyright © 2011-2022 走看看