@pytest.mark.parametrize('参数化名称',参数化值) |
import pytest # 登录参数 data = [('anjing', 'anjing_pwd'), ('test', 'test_pwd'), ('admin', 'admin_pwd')] class Test_01: # 通过parametrize进行参数化 @pytest.mark.parametrize('user, pwd', data) def test_01(self, user,pwd): print('---用例01---') print('登录的用户名:%s' % user) print('登录的密码:%s' % pwd) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest # 登录参数 data = [('anjing', 'anjing_pwd'), ('test', 'test_pwd'), ('admin', 'admin_pwd')] class Test_01: # 通过parametrize进行参数化 @pytest.mark.parametrize('user,pwd', data, ids=['user name is anjing','user name is test','user name is admin']) def test_01(self, user,pwd): print('---用例01---') print('登录的用户名:%s' % user) print('登录的密码:%s' % pwd) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest # 登录参数 data = [('anjing', 'anjing_pwd'), pytest.param('test', 'test_pwd',marks=pytest.mark.skip), ('admin', 'admin_pwd')] class Test_01: # 通过parametrize进行参数化 @pytest.mark.parametrize('user,pwd', data, ids=['user name is anjing','user name is test','user name is admin']) def test_01(self, user,pwd): print('---用例01---') print('登录的用户名:%s' % user) print('登录的密码:%s' % pwd) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest # 登录参数 data = ['anjing', 'test', 'admin'] data1 = ['123', '456', '789'] class Test_01: # 通过parametrize进行参数化 @pytest.mark.parametrize('user', data) @pytest.mark.parametrize('pwd', data1) def test_01(self, user, pwd): print('---用例01---') print('登录的用户名:%s' % user) print('登录的密码:%s' % pwd) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest data = [{'user': "anjing", 'pwd': "123456"}, {'user': "test", 'pwd': "123456"}, {'user': "admin", 'pwd': "123456"}] class Test_01: @pytest.mark.parametrize('user', data) def test_01(self, user): print('账号信息:%s' % user) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest data = [{'user': "anjing", 'pwd': "123456"}, {'user': "test", 'pwd': "123456"}, {'user': "admin", 'pwd': "123456"}] @pytest.fixture(params=data) def login(request): print('打开浏览器') yield request.param print('关闭浏览器') class Test_01: def test_01(self, login): print('用户名:%s' % login['user']) print('密码:%s' % login['pwd']) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest data = [['anjing', 'anjing_pwd'], ['test', 'test_pwd'], ['admin','admin_pwd']] @pytest.fixture(params=data) def login(request): print('打开浏览器') yield request.param print('关闭浏览器') class Test_01: def test_01(self, login): print('用户名:%s' % login[0]) print('密码:%s' % login[1]) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest data = [('anjing', 'anjing_pwd'), ('test', 'test_pwd'), ('admin','admin_pwd')] @pytest.fixture(params=data) def login(request): print('打开浏览器') yield request.param print('关闭浏览器') class Test_01: def test_01(self, login): print('用户名:%s' % login[0]) print('密码:%s' % login[1]) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
import pytest data = [['anjing', 'anjing_pwd'], ['test', 'test_pwd'], ['admin','admin_pwd']] @pytest.fixture(params=data, ids=['user=anjing','user=test','user=admin']) def login(request): print('打开浏览器') yield request.param print('关闭浏览器') class Test_01: def test_01(self, login): print('用户名:%s' % login[0]) print('密码:%s' % login[1]) def test_02(self): print('---用例02---') if __name__ == '__main__': pytest.main(['-vs']) |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |