Pytest参数化(1)_parametrize()
@pytest.mark.parametrize(args_name,args_value)
args_name:参数名称,用于将参数传递给函数
args_value:参数值(列表和字典列表,元组和字典元组),有n个值则用例执行n次。
传单个参数:
class TestCompany(): @pytest.mark.parametrize("name",['Ellie','Jane','Ruby']) def test_company3(self,name): print("Login by"+ name)
传多个参数:
import pytest class TestCompany(): @pytest.mark.parametrize("name,age",[['Ellie',18],['Jane',19],['Ruby',20]]) def test_company3(self,name,age): print("Login by"+ name) print('His name is'+ str(age))