手把手教你学会接口自动化系列十九-引入测试框架pytest之后修改优化其他代码

demo2.py为了让pytest识别到,我们会把demo2命名为test_demo2,优化后如下:


# !/usr/bin/env python

# -*- coding: utf-8 -*-

# @Time : 2024/01

# @Author : Laopi

import json

import logging



import allure



from testcase.conftest import *



@allure.epic("添加线索模块")

class TestAddScence:

def test_addXiansuo(self,get_baseUrl,get_workbook,get_token):

baseUrl = get_baseUrl

logging.info(baseUrl['host'])

workbook = get_workbook

workbook._active_sheet_index = 1

sheet = workbook.active

cookie = get_token

url = baseUrl['host'] + sheet.cell(row=2, column=2).value

for i in range(6, sheet.max_row + 1):

headers = json.loads(sheet.cell(i, 2).value)

headers.update({'Admin-Token': cookie})

if headers['Content-Type'] == 'application/json':

data = json.dumps(json.loads(sheet.cell(i, 3).value))

else:

data = json.loads(sheet.cell(i, 3).v

你可能感兴趣的:(接口自动化测试,软件测试,测试工具,自动化)