【测试】【Debug】pytest运行后print没有输出

python 复制代码
import pytest
def test_good():
    for i in range(1000):
        print(i)

def test_bad():
    print('this should fail!')
    assert False

比如上述程序,运行之后只能看到输出了'this should fail!';但是debug版的测试运行后又能看到test_good函数中的输出。

这是为什么呢?

  1. pytest自动会capture通过的那些测试用例运行中所print出来的output;而failed的那些测试用例则会打印其中运行过的print的输出。
  2. 如果想要获取全部的输出:
    在终端中运行下面其中一行即可 这两种都可以
shell 复制代码
pytest name.py --capture=no     # show print statements in console

pytest name.py -s               # equivalent to previous command
相关推荐
我的xiaodoujiao11 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 48--本地环境部署Jenkins服务
python·学习·测试工具·pytest
我的xiaodoujiao11 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 49--CI/CD-开始探索使用Jenkins
python·学习·测试工具·ci/cd·jenkins·pytest
测试渣2 天前
测试左移实战:如何在需求阶段拦截80%缺陷?
selenium·pytest·测试覆盖率
一次旅行2 天前
测开每日AI提效指令(Python+pytest专属)
python·pytest·测试总结
一次旅行2 天前
接口自动化测试模板
数据库·python·pytest
Kingairy3 天前
Claude Python3+pytest Code Review skill.md
pytest·代码复审
姚青&4 天前
Pytest 参数化与调度执行
pytest
薯条不要番茄酱4 天前
【测试实战篇】“发好论坛”接口自动化测试
python·功能测试·测试工具·单元测试·测试用例·pytest·测试覆盖率
weixin_419658314 天前
当Pytest遇见AI:基于Trae的接口测试用例全自动生成实践
人工智能·python·测试工具·测试用例·pytest·ai编程
@zulnger6 天前
selenium+pytest 自动化测试实战项目(登录升级版)
selenium·测试工具·pytest