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的gil是什么?Python中gil的介绍

Python队列的定义与使用方法实例详解

十分钟利用Python制作属于你自己的个性logo

Python如何调用dll库

pandas妙招之 dataframe基础运算以及空值填充

啥是佩奇,Python 告诉你!

Python--堡垒机的介绍

pytho中字典操作方法介绍(代码示例)

什么是Python解释器

Python的库是什么意思

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




打赏

取消

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

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

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

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

评论

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

    正在狠努力加载,请稍候...