利用parameterized实现数据驱动,代码少快爽
# -*- coding: utf-8 -*-
import unittest
from parameterized import parameterized
from test import readCsvDict
import os
import urllib.request
class Test(unittest.TestCase):
@parameterized.expand(readCsvDict()) # ------>数据驱动<------
def test_01(self, a, b):
url = b
file_path = 'G:/business_auto/png/'
file_name = a
if not os.path.exists(file_path):
os.makedirs(file_path)
file_suffix = os.path.splitext(img_url)[1]
print(file_suffix)
filename = '{}{}{}'.format(file_path, file_name, file_suffix)
print(filename)
# 保存文件
urllib.request.urlretrieve(url, filename=filename)