天天看点

软件测试系列:pytest框架用例和运行规范

作者:Ray软件测试

建议命令规范

1、模块名必须为test_开头或者以_test结尾
2、函数或者方法,必须以test开头
3、class类名必须以Test开头
4、模块以test_开头,建议test_+业务名称
5、类的首字母大写,遵循驼峰命名规则
6、方法以test_开头,遵循test_+固定位数字+下划线+业务名称,例如test_01_order_list           

运行案例

import pytest


def func():
    print("我是普通函数")

def test_func():
    print("我是测试函数")

class Testlogin:
    def test01(self):
        print("我是测试类中的测试函数")


if __name__ == '__main__':
    pytest.main()
"""
testone.py::test_func PASSED                                             [ 50%]我是测试函数
testone.py::Testlogin::test01 PASSED                                     [100%]我是测试类中的测试函数
"""           

命令运行

软件测试系列:pytest框架用例和运行规范

主函数运行

软件测试系列:pytest框架用例和运行规范

命令行的参数都可以在pytest.main()中使用。

软件测试系列:pytest框架用例和运行规范