cohhi / application-Test

软件测试
http://411.free.svipss.top/blog/resources/applicationtest/index.html
0 stars 0 forks source link

ddt导入外部读取方法,需要解包两次,艹 #11

Open cohhi opened 1 year ago

cohhi commented 1 year ago
#读取test.csv文件
import csv

def readFile():
   data = []
   with open('test.csv','r')as file:
      reader=csv.reader(file)
      for i in reader:
      data.append(i)
   return data
import readFile
from ddt import ddt,data,unpack
import unittest
data=readFile()

class Test(unittest.TestCase):
   @data(*data)
   @unpack
   @unpack
   # 需要解包两次 艹
   def test(self,value)
      print(value)
cohhi commented 1 year ago

折腾了两个小时,艹

cohhi commented 1 year ago

另一种解决思路

import csv

def readFile():
    data = csv.reader(open('test.csv', encoding='utf-8'))
    next(data)
    dataList = []
    for i in data:
        dataList.append(i)
    return dataList

print(*readFile()) #打印时解包