1. 单个参数

@pytest.mark.parametrize() 在括号中填写参数名称,以及一个列表,列表中每个参数用括号进行保存

2. 多个参数

@pytest.mark.parametrize('eee,ssss', InfoList) 在括号中填写多个参数的名称,以及列表,列表中以元祖格式展示一对参数

 

import pytest


class TestAAA:

    @pytest.mark.parametrize('x', [(1), (2), (6)])
    def test_demo(self, x):
        assert x == 1

    InfoList = [("3+5", 8), ("2+4", 6), ("6*9", 54)]

    @pytest.mark.parametrize('eee,ssss', InfoList)
    def test_param(self, eee, ssss):
        assert eval(eee) == ssss
        print('被加载测试数据为{}'.format(eee))

  

相关文章:

  • 2021-11-16
  • 2021-09-15
  • 2022-12-23
  • 2022-01-24
  • 2021-11-17
猜你喜欢
  • 2021-11-15
  • 2021-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案