Pytest @pytest.mark.parametrize装饰器

示例:

# -*- coding: utf-8 -*-

'''
业务逻辑相同,输入参数量较大, 使用 pyetst内置装饰器@pytest.mark.parametrize('参数名',参数列表)
'''

import pytest

@pytest.mark.parametrize('x,y',[(1,2),(3,4)])
def test_sum(x,y):
    sum = x+y
    print('\n')
    print(sum)

if __name__ == '__main__':
    pytest.main(['test_scripts02.py','-s'])

控制台输出:

============================= test session starts =============================
platform win32 -- Python 3.8.2, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: E:\PycharmProjects\Pytest-Webui-songqin
plugins: allure-pytest-2.8.40, html-3.1.1, metadata-1.11.0
collected 2 items

test_scripts02.py 

3
.

7
.

============================== 2 passed in 0.09s ==============================

 

posted @ 2021-08-30 20:49  Avicii_2018  阅读(57)  评论(0)    收藏  举报