完整的参数
使用pytest --markers
1,usefixtures
@pytest.mark.usefixtures("cleandir", "anotherfixture") def test():
2,parametrize
直接传入参数/把参数组合/对参数进入再次标记
@pytest.mark.parametrize('input1, input2',[(1,2),(2,3),(3,4)]) def est_01(self,input1, input2): print('执行1') assert input1 + input2 == 31 @pytest.mark.parametrize('input1', [1,2]) @pytest.mark.parametrize('input2', [3,4]) def est_01(self, input1, input2): print('执行1') assert input1 + input2 == 31 @pytest.mark.parametrize('input2', [3, 4,pytest.param(5, marks=pytest.mark.skip)]) def test_01(self, input2): print('执行1') assert input2 == 31
3,skip/skipif/xfail
@pytest.mark.skip(reason="no way of currently testing this") def test_the_unknown(): ...
4,自定义mark标签
1,首先需要注册标签,才能使用
注册方式:在ini文件中添加
[pytest] markers = login: marks tests as slow (deselect with '-m "not slow"') serial
注册方式2:使用pytest_configure钩子函数
def pytest_configure(config): config.addinivalue_line( "markers", "env(name): mark test to run only on named environment" )
2,使用
@pytest.mark.login class TestLoginSuccess: @pytest.mark.parametrize('input1,inp3',[(1,2),(2,3),(3,4)]) def test_01(self,input1,inp3): print('执行1') assert input1 +inp3 == 31
3,使用-m选择指定标签的用例,同样在标签前面添加not,代表运行所有不是指定标签的用例
想要同时执行多个标签的用例,使用or , 想要执行既满足标签a又满足标签b的用例使用 and,,,并且注意 标签的引号一定要是双引号
cmd = 'python3 -m pytest -k TestLoginSuccess -s -m "not login" app '
os.system(cmd)
4,后续