[英]Why code coverage not 100%? pytest-cov
為什么我沒有獲得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%
html輸出將向您顯示缺少的行
pytest --cov=paths --cov-report=html
然后從新創建的htmlcov文件夾中打開index.html。
這是一個演示100%測試覆蓋率的視頻。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.