python接口自动化之配置文件运行

在开始学习python时, 运行一段代码用的都是main方法,如下

import pytest

class TestOrder:

    def test_001(self):
        print('用例1')

    def test_002(self):
        print('用例2')

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

 

在学习接口自动化时, 项目一般都会要求使用pytest.ini  结合 all.py文件来运行代码。以下是使用说明

 

pytes.ini :首先在项目根目录下新建一个pytest.ini文件(记得安装ini文件插件)

 

 

 

然后在pytest.ini中写入配置参数。这只是一般级参数,更多参数请查阅https://www.cnblogs.com/zouzou-busy/p/11323606.html。

参数及说明

[pytest]  :标记pytest.ini文件是配置文件
addopts = -s  :命令行的参数,用空格隔开,相当于main方法里的pytest.main(['-s'])
testpaths = ./testcase  :寻找这个testcase 目录下以test开头的py文件,并执行
python_files = test_*.py  :修改pytest默认文件命令规则
python_classes = Test*  :修改pytest默认类命令规则
python_functions = test*  :修改默认用例命令规则

 

posted @ 2022-11-13 22:49  博无止境  阅读(155)  评论(0)    收藏  举报