日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python代码覆盖率测试_unittest+coverage单元测试代码覆盖操作实例详解_python

發布時間:2025/3/15 python 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python代码覆盖率测试_unittest+coverage单元测试代码覆盖操作实例详解_python 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇文章主要為大家詳細介紹了unittest+coverage單元測試代碼覆蓋操作的實例,具有一定的參考價值,感興趣的小伙伴們可以參考一下

基于上一篇文章,這篇文章是關于使用coverage來實現代碼覆蓋的操作實例,源代碼在上一篇已經給出相應鏈接。

本篇文章字用來實現代碼覆蓋的源代碼,整個項目的測試框架如下:

就是在源代碼的基礎上加了一個CodeCover.py文件,執行該文件會在目錄CoverageReport生成相應的覆蓋報告。如下是CodeCover.py的源碼:

#coding=utf8

import os

import time

def findTestWithPath():

current_dir=os.getcwd()

folderName=os.listdir(current_dir)

#print folderName

#獲取到測試文件所在目錄

TestSuit=[suite for suite in folderName if not suite.find("TestSuit")]

#用來保存測試文件

testfile=[]

withPathFile=[]

for suite in TestSuit:

#獲取測試目錄下的所有測試文件

testfile=testfile+os.listdir(".\\"+suite)

for withPath in testfile:

withPath=current_dir+"\\"+suite+"\\"+withPath

withPathFile.append(withPath)

del testfile

#把testfile中的py文件挑選出來

withPathFile=[name for name in withPathFile if not "pyc" in name]

#print testfile

print withPathFile

return withPathFile

def codeCoverage():

now = time.strftime("%Y%m%d%H%M")

htmlReport=os.getcwd()+"\\"+"CoverageReport"

htmlCmd="coverage html -d " + htmlReport +"\\"+now

for pyfile in findTestWithPath():

runPyCmd="coverage run " + pyfile

if os.path.exists(htmlReport) :

os.system(runPyCmd)

os.system(htmlCmd)

else:

os.mkdir(htmlReport)

os.system(runPyCmd)

os.system(htmlCmd)

if __name__=="__main__":

codeCoverage()

運行結果圖:

相關推薦:

以上就是unittest+coverage單元測試代碼覆蓋操作實例詳解_python的詳細內容,更多請關注php中文網其它相關文章!

本文原創發布php中文網,轉載請注明出處,感謝您的尊重!

總結

以上是生活随笔為你收集整理的python代码覆盖率测试_unittest+coverage单元测试代码覆盖操作实例详解_python的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。