为什么我没有100%的代码覆盖率?!
所有的方法都经过测试..。
如何计算代码覆盖率百分比?
代码
import os
def get_root_dir():
return os.path.abspath(os.path.join(os.path.sep, os.path.dirname(os.path.realpath(__file__)), '../../'))
def get_coverage_report_dir():
return os.path.join(os.path.sep, get_root_dir(), 'coverage_report')测试
import unittest
class TestPaths(unittest.TestCase):
def test_paths(self):
import src.utils.paths as paths
self.assertTrue(paths.get_root_dir().endswith('myproject'))
self.assertTrue(paths.get_root_dir() in paths.get_coverage_report_dir() and paths.get_coverage_report_dir().endswith('coverage_report'))报告
---------- coverage: platform win32, python 2.7.14-final-0 -----------
Name Stmts Miss Cover
------------------------------------------------------
src\utils\__init__.py 0 0 100%
src\utils\example_util_module.py 2 0 100%
src\utils\paths.py 5 3 40%
------------------------------------------------------
TOTAL 7 3 57%发布于 2019-05-19 22:11:11
html输出将显示缺少的行。
pytest --cov=paths --cov-report=html
然后从新创建的htmlcov文件夹中打开index.html。
这是一段视频,展示了100 %的测试覆盖率。

https://stackoverflow.com/questions/48663241
复制相似问题