@pytest.mark.parametrize()
怎么说,三大功能:
查看测试用例test_case_9、10、11
# coding=utf-8
import pytest
class Testlogin001:
# 单参数单值
@pytest.mark.parametrize('arg', [1])
def test_case_9(self, arg):
print("传入的值为:{}".format(arg))
assert arg == 1
# 单参数多值
@pytest.mark.parametrize('arg',['abc',1,{'a':1,'b':3},(4,5)])
def test_case_10(self, arg):
print(f"传入的值为:{arg}")
# 多参数多值
@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("5-2", 3), ("5*2", 10)])
def test_case_11(self, test_input, expected):
print(f"原值:{test_input} 期望值{expected}")
assert eval(test_input) == expected
if __name__ == "__main__":
pytest.main(['-vs', 'test_1.py'])
C:\Python39\python.exe D:/se_frame/Cases/MapAaaCases/test_1.py
test_1.py::Testlogin001::test_case_9[1]
启动浏览器
传入的值为:1
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_10[abc]
启动浏览器
传入的值为:abc
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_10[1]
启动浏览器
传入的值为:1
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_10[arg2]
启动浏览器
传入的值为:{'a': 1, 'b': 3}
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_10[arg3]
启动浏览器
传入的值为:(4, 5)
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_11[3+5-8]
启动浏览器
原值:3+5 期望值8
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_11[5-2-3]
启动浏览器
原值:5-2 期望值3
PASSED
退出浏览器
test_1.py::Testlogin001::test_case_11[5*2-10]
启动浏览器
原值:5*2 期望值10
PASSED
退出浏览器