python做数据驱动

python做数据驱动

python代码如下:

import unittest
from openpyxl import load_workbook
from openpyxl.styles import Font
from openpyxl.styles.colors import RED, GREEN


wb = load_workbook(r"C:\Users\test\Desktop\q.xlsx")
ws = wb.get_sheet_by_name('testData')
rows = ws.max_row

red = Font(name='Calibri', size=14, bold=False, italic=False, vertAlign=None, underline='none', strike=False, color=RED)

Gr = Font(name='Calibri', size=14, color=GREEN)


def add(num1, num2):
return num1 + num2


class TestGetIP(unittest.TestCase):
total_count = 0
success_count = 0
fail_count = 0

def testRun(self):
for row in range(2, rows+1):
self.total_count += 1
name = ws.cell(row=row, column=1).value
param1 = ws.cell(row=row, column=2).value
param2 = ws.cell(row=row, column=3).value
ep = ws.cell(row=row, column=4).value
with self.subTest(msg=name):
try:
self.assertEqual(ep, add(param1, param2))
ws.cell(row=row, column=5).value = "pass"
ws.cell(row=row, column=5).font = Gr
self.success_count += 1
except Exception as e:
ws.cell(row=row, column=5).value = str(e)
ws.cell(row=row, column=5).font = red
self.fail_count += 1
result = "用例执行结果:" \
"共执行%d条用例,成功%d条,失败%d条" % (self.total_count, self.success_count, self.fail_count)
ws.cell(row=rows + 1, column=6).value = result
print()
print(result)
wb.save(r"C:\Users\h\Desktop\q.xlsx")

运行结果如下:
 
   
  

 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值