【pytest学习】pytest.main()

基本用法##

pytest.main()函数是用于启动测试运行的入口点。它可以在命令行中直接使用,也可以在脚本中以编程方式调用。
以下是一个简单的示例:

import pytest
if __name__=="__main__":
     pytest.main()

执行当前目录下的所有测试文件

使用pytest.main(‘目录名’)运行特定的测试模块

只想运行特定的测试模块。这可以通过向pytest.main()传递模块路径来实现。

import pytest
if __name__ =='__main__':
    pytest.main(["practice/test_get.py"]) //注意如果main函数所在的文件跟测试用例不在同一个目录,需要指定一下,不然会提示没有这个文件

使用pytest.main(测试文件名:用例函数)运行特定的测试函数:冒号分割

    def test_one(self):
        assert 1==1

    def test_two(self):
        assert 2==1

    def test_three(self):
        assert 3==4
import pytest
if __name__ =='__main__':
    pytest.main(["practice/test_get.py::test_two"])

使用pytest.main()运行指定模块 指定类 指定用例:冒号分割

pytest.main([‘test_reg.py::TestClass::test_method’])

 pytest.main(["practice/test_get.py::Test_Rule::test_two"])//Test_Rule是类名,test_two是用例函数

其它参数

pytest.main([‘-vs’, ‘./test_case/test_demo.py::Test_case’])

-v: 丰富信息模式, 输出更详细的用例执行信息
-s: 显示程序中的print/logging输出
-q: 不输出环境信息

-m=xxx: 运行打标签的用例
-reruns=xxx,失败重新运行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>