【测试】【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
相关推荐
糖果店的幽灵4 天前
软件测试接口测试从入门到精通:Python接口自动化 - pytest测试框架
软件测试·python·功能测试·自动化·pytest·接口测试
2601_961875244 天前
花生十三资料1200题|题库|刷题
conda·pytest·pillow·pip·web3.py·ipython·gunicorn
某人辛木5 天前
Web自动化测试
前端·python·pycharm·pytest
淡漠的蓝精灵7 天前
pytest-xdist:把 pytest 测试分发到多核 CPU 执行
其他·pytest
弹简特8 天前
【接口自动化】03-YAML详解及Parametrize数据驱动
自动化·pytest
007张三丰10 天前
软件测试专栏(11/20):测试框架开发:pytest深度解析与插件体系
运维·服务器·自动化测试·pytest·测试框架
我的xiaodoujiao10 天前
API 接口自动化测试详细图文教程学习系列25--继续处理testCase中的数据
python·学习·测试工具·pytest
xiaobai17811 天前
pytest+playwright实现UI自动化(4)-上夹具fixture
ui·自动化·pytest·playwright
弹简特11 天前
【接口自动化】02-Pytest固件fixture核心机制与Allure企业级报告实战
自动化·pytest·测试