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


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

#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()

运行结果图:

相关推荐:

关于phpunit与Selenium取coverage的配备(原创)

以上就是unittest+coverage单元测试代码覆盖操作实例详解_python的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

Python空字典怎么写

Python如何进行数据类型转换

Python怎么解压rar文件

Python中变量和数据类型介绍

用pip升级所有包怎么操作

Python中如何对字典排序

Python基于win32ui模块创建弹出式菜单

Python--条件语句与循环语句

Python之post登录实例代码

Python数据分析要学什么

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...