Python自动化测试中使用正则表达式根据测试用例名称来过滤选择测试用例工具

Python自动化测试中使用正则表达式根据测试用例名称来过滤选择测试用例工具
摘要由CSDN通过智能技术生成
#!/usr/bin/python
# fileName: runtest
# encoding = utf-8

import os,sys,getopt,re,time
os.popen('yum install -y unittest-xml-reporting')
import unittest,xmlrunner


def add_path():
    if '/opt/mailcontrol/modules/TQPlugin/' not in sys.path:
        sys.path.append('/opt/mailcontrol/modules/TQPlugin/')
    if '/opt/mdmi/modules' not in sys.path:
        sys.path.append('/opt/mdmi/modules')
    print ''


def walk_dir(dir, modules, servers):
    '''
    Traverse all spcified directories along with sub-directories to present matched files and directories.
    '''
    matched_files = []
    matched_dirs = []
    comp = re.compile('^test_.+\.py$')

    for thisdir, subdirs, fileshere in os.walk(dir):
        os.chdir(thisdir)
        for filename in fileshere:
            if filename.endswith('.py'):
                if thisdir not in sys.path:
                    sys.path.insert(0, thisdir)
                if servers:
                    #m_file = re.search('^test_.+\.py$', filename)
                    if comp.search(filename):
                        file = open(filename, 'r')
                        line_note = ''
                        for i in range(20):
                            line = file.readline().strip('\n')
                            line_note = line_note + line
                        note_obj = re.search(r'(\"\"\").*?\1|(\'\'\').*?\2', line_note)
                        if note_obj:
                            note = note_obj.group()
                            for server in servers:
                                #note = __import__(m_file.group(1)).__doc__
                                #if not note: continue
                                if re.search('%s' %server, note):
                                    if not modules:
                                        #if re.search('^test_.+\.py$', filename):
                                        if comp.search(filename):
                                            matched_files.append(filename)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值