@pytest.mark.parametrize装饰器可以实现测试用例参数化

@pytest.mark.parametrize("参数名",列表数据)

参数名:用来接收每一项数据,并作为测试用例的参数

列表数据:一组测试数据

 

 @pytest.mark.parametrize()只一个参数时,是把list的每个元素当做形参传入的,会assert每次执行结果。

一、传一个参数时,两种写法都可以,具体看以下实例:

'''写法一'''
@pytest.mark.parametrize('name',['lili','hello','sophia'])
def test_name(name):
print(name)



'''写法二'''
name_list=['lili','hello','sophia']
@pytest.mark.parametrize('name',name_list)
def test_name(name):
print (name)

二、传多个参数


相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2021-12-13
  • 2021-08-22
  • 2021-11-15
  • 2021-05-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2021-11-25
  • 2022-02-25
相关资源
相似解决方案