测试的时候经常需要使用一些方法都整理放在一起,方便调用

首先一些基本的配置引入

 localReadConfig = readConfig.ReadConfig()
proDir = readConfig.proDir
log = Log.get_log() caseNo = 0

根据xls_name和sheet_name来读取数据

 def get_xls(xls_name, sheet_name):
"""
get interface data from xls file
:param xls_name:
:param sheet_name:
:return:
"""
cls = []
# get xls file's path
xls_path = os.path.join(proDir, 'testFile', 'case', xls_name)
# open xls file
file = xlrd.open_workbook(xls_path)
# get sheet by name
sheet = file.sheet_by_name(sheet_name)
# get one sheet's rows
nrows = sheet.nrows
for i in range(nrows):
if sheet.row_values(i)[0] != u'case_name':
cls.append(sheet.row_values(i))
return cls

将结果写入到excel中

 def write_result_into_xls(xls_path, sheet, wb, result, row, col):
sheet.write(row, col, result)
   wb.save(xls_path)
 def write_results_into_xls(xls_name, sheet_name, results, col):
xls_path = os.path.join(proDir, 'testFile', 'case', xls_name)
rb = xlrd.open_workbook(xls_path)
wb = copy.copy(rb)
sheet = wb.get_sheet(sheet_name)
for i in range(len(results)):
write_result_into_xls(xls_path, sheet, wb, results[i], i+1, col)

正则表达式匹配

 用import.re导入正则表达式模块
用re.complie()函数创建一个Regex对象(记得使用原始字符串)
向Regex对象的search()方法传入想查找的字符串。它返回一个Match对象
调用Macth对象的group()方法,返回实际匹配文本的字符串

最新文章

  1. StartUML反向(逆向)Java工程通过代码生成类图
  2. 支持Java Spring MVC
  3. Redis总结(二)C#中如何使用redis
  4. OpenResty 安装及使用(第一篇安装)
  5. 【UR #4】元旦三侠的游戏(博弈论+记忆化)
  6. Java日志性能
  7. 函数malloc的实现源代码
  8. logstash+elasticsearch+kibana快速搭建日志平台
  9. socket编程部分API
  10. C# 微信开发-----微信会员卡(三)激活会员卡
  11. gulp + gulp-better-rollup + rollup 构建 ES6 开发环境
  12. POI 海量数据/大数据文件生成SXSSFWorkbook使用简介
  13. js----DOM对象(事件)
  14. nyoj-0469-擅长排列的小明 II(找规律)
  15. Windows下Python安装: requires numpy+mkl 和ImportError: cannot import name NUMPY_MKL
  16. C语言之选择结构
  17. Egret 菜鸟级使用手册--第二天
  18. Scrapy爬取美女图片第三集 代理ip(下)
  19. linux nginx 配置php
  20. C# 使用this的形参

热门文章

  1. PHP验证信用卡卡号函数
  2. Windows平台JxCore打包
  3. HDU 2092 (将表达式变成一元二次方程形式)
  4. 基于kafka rest实现资源访问服务化(实战)
  5. 第三天-零基础学习python
  6. 产品 | What's产品经理
  7. IDEA(2018.3.2)
  8. 使用泛型与不使用泛型的Map的遍历
  9. python教程(二)·条件语句
  10. Zabbix 3.4.11版本 自定义监控项