python怎么测试运行_python + pytest基本使用方法(运行测试&测试报告)

import pytest

# 1.运行名称中包含某字符串的测试用例

#名称中含add 的测试用例

# 执行: pytest -k add test_assert.py

# 2.减少测试的运行冗长

# 执行: pytest -q test_assert.py

# 3.如果出现一条测试用例失败,则退出测试

# 执行: pytest -x test_assert.py

# 4.运行测试目录 相对路径或绝对路径都行

# 执行: pytest ./test_dir

# 5.指定测试类或方法执行

# 指定运行test_fixtures_02.py文件中的TestMultiply类下的test_multiply_5_6方法

# 文件名、类名和方法名之间用::符合分隔

# 执行: pytest test_fixtures_02.py::TestMultiply::test_multiply_5_6

# 6.通过main()方法运行测试

# if __name__ == ‘__main__‘:

# if __name__ == ‘__main__‘:

# pytest([‘-s‘,‘./test_dir‘])

#生成测试报告

# 1.生成JUnit XML 文件

# 执行: pytest ./test_dir --junit-xml=./report/log.xml

# 2.生成在线测试报告

# 执行: pytest ./test_dir --pastebin=all

# 3.pytest-html 可以生成HTML格式的测试报告

# 安装 pip install pytest-html

# 执行: pytest ./ --html=./report/result.html

原文:https://www.cnblogs.com/Teachertao/p/11902087.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值