【测试】【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
相关推荐
清水白石00810 小时前
《解锁 Python 潜能:从异步基石到 pytest-asyncio 高级测试实战与最佳实践》
运维·python·pytest
清水白石0082 天前
Fixture 的力量:pytest fixture 如何重新定义测试数据管理
数据库·python·pytest
七夜zippoe3 天前
单元测试进阶:pytest高级特性与实战秘籍
单元测试·pytest·持续集成·猴子补丁·fixtrue
我的xiaodoujiao7 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 48--本地环境部署Jenkins服务
python·学习·测试工具·pytest
我的xiaodoujiao7 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 49--CI/CD-开始探索使用Jenkins
python·学习·测试工具·ci/cd·jenkins·pytest
测试渣9 天前
测试左移实战:如何在需求阶段拦截80%缺陷?
selenium·pytest·测试覆盖率
一次旅行9 天前
测开每日AI提效指令(Python+pytest专属)
python·pytest·测试总结
一次旅行9 天前
接口自动化测试模板
数据库·python·pytest
Kingairy10 天前
Claude Python3+pytest Code Review skill.md
pytest·代码复审
姚青&11 天前
Pytest 参数化与调度执行
pytest