""" ------------------------------------ @Time : 2019/7/25 19:18 @Auth : linux超 @File : test_parametrize.py @IDE : PyCharm @Motto: Real warriors,dare to face the bleak warning,dare to face the incisive error! @QQ : 28174043@qq.com @GROUP: 878565760 ------------------------------------ """ import pytest
data_1 = [ [1, 2, 3], pytest.param(3, 4, 8, marks=pytest.mark.skip) ]
def add(a, b): return a + b
@pytest.mark.parametrize('a, b, expect', data_1) def test_parametrize_1(a, b, expect): print('\n测试数据为\n{},{}'.format(a, b)) assert add(a, b) == expect
if __name__ == '__main__': pytest.main(['-vs']) 输出 ============================= test session starts ============================= platform win32 -- Python 3.7.2, pytest-4.3.1, py-1.8.0, pluggy-0.9.0 -- C:\Programs\Python\Python37-32\python.exe cachedir: .pytest_cache metadata: {'Python': '3.7.2', 'Platform': 'Windows-7-6.1.7601-SP1', 'Packages': {'pytest': '4.3.1', 'py': '1.8.0', 'pluggy': '0.9.0'}, 'Plugins': {'rerunfailures': '7.0', 'metadata': '1.8.0', 'html': '1.20.0'}, 'JAVA_HOME': 'D:\\JDK'} rootdir: E:\CnblogCode\pytest_parametrize, inifile: plugins: rerunfailures-7.0, metadata-1.8.0, html-1.20.0 collecting ... collected 2 items
test_parametrize.py::test_parametrize_1[1-2-3] 测试数据为 1,2 PASSED test_parametrize.py::test_parametrize_1[3-4-8] SKIPPED
===================== 1 passed, 1 skipped in 0.17 seconds =====================
Process finished with exit code 0 |