Pytest07-pytest.ini配置文件

Pytest07-pytest.ini配置文件


高清B站视频链接

1.pytest配置文件

固定名称:pytest.ini

作用域:当前目录及子目录

具体配置功能见下:

[pytest]
# 01 把命令行参数自动添加到这里
addopts = -s -v --html=./report/report2023.html
# 02 指定执行的用例的目录
testpaths = ./script
# 03 修改默认的测试文件名规则
python_files = auto*.py
# 04 修改默认的类命名规则
python_classes = Auto* B* C*
# 05 测试函数/方法的命名规则
python_functions = auto*

pytest.ini文件中如果有中文,可能会出编码问题,需要把文件设置为gbk
1.选择pytest.ini文件
2.点击 file选项
3.选择 File Encoding后
4.选择 GBK
5.选择convert

2.pytest常用插件

插件列表网址:https://docs.pytest.org/en/latest/reference/plugin_list.html
pytest-html插件
安装:
pip install pytest-html
使用方法: 命令行格式:pytest --html=用户路径/report.html

3. 代码案例

代码目录结构
代码目录结构
文件:pytest.ini

[pytest]
# 01 把命令行参数自动添加到这里
addopts = -s -v --html=./report/report2023.html
# 02 指定执行的用例的目录
testpaths = ./doc
# 03 修改默认的测试文件名规则
python_files = auto*.py
# 04 修改默认的类命名规则
python_classes = Auto* B* C*
# 05 测试函数/方法的命名规则
python_functions = auto*

文件:test_case01.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 作者:扶摇
import pytest

def test01():
    print('用例一')

if __name__ == '__main__':
    pytest.main()

文件:doc/auto01.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 作者:扶摇
def test01():
    print("test01")

def auto01():
    print("auto")
class B:
    def test03(self):
        print("test03")

文件:doc/test_aabb.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 作者:扶摇
# 测试函数
def test02():
    print("doc目录下的用例test02")

class TestShopping:
    # pytest测试类不能使用构造方法
    # def __init__(self):
    #     print("构造方法")

    # 测试方法
    def test03(self):
        print("类下的用例")

测试技术交流请联系我
在这里插入图片描述
备注CSDN扶摇

【学习软件测试/Python自动化测试技术/领取Python自动化测试学习路线图/简历优化】
视频链接:
课程服务介绍

自动化全栈学习路线图讲解

软件测试面试合集

Python编程刷题合集

Pytest入门到实战

Python接口自动化合集

PythonWeb自动化合集

性能测试合集

Jmeter接口自动化测试实战全集

2023GPT探索发现合集

加微信(备注CSDN扶摇)即可免费领取下面的自动化测试资料和一份软件测试面试宝典
在这里插入图片描述
在这里插入图片描述

  • 21
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

测试老宅男扶摇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值