一、Parameterized安装命令
常见安装:pip install parameterized
或使用国内豆瓣镜像源安装:pip install parameterized -i https://pypi.douban.com/simple
shell页面(安装页面cmd内)
C:\Users\S3214>pip install parameterized -i https://pypi.douban.com/simple
Looking in indexes: https://pypi.douban.com/simple
Requirement already satisfied: parameterized in c:\programs\python\python38\lib\site-packages (0.9.0)
WARNING: You are using pip version 19.2.3, however version 23.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
二、核心代码
@parameterized.expand()
Code
#参数化
# 下载pip install parameterized -i https://pypi.douban.com/simple
# @parameterized.expand()
# 效果,减少重复操作
import unittest
# 导包错误不是import parameterized 而是 from parameterized import parameterized
from parameterized import parameterized
from mathfunc import add, minus, my_random
# 写测试用例(继承mathfunc中写好的函数)
class add_minus_test(unittest.TestCase):
# 参数化---》减少重复操作()
@parameterized.expand([(5,6,11),(2,-3,-1),(-3,-2,-5),(2,0,2)])
def test_add(self,a,b,c):
num = add(a, b)
self.assertEqual(c, num)