【测试】【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
相关推荐
专职14 小时前
pytest详细教程
开发语言·python·pytest
乄捷径14 小时前
pytest入门到熟练
pytest
专职14 小时前
pytest+requests+allure生成接口自动化测试报告
开发语言·python·pytest
小熊出擊1 天前
【pytest】fixture 内省(Introspection)测试上下文
python·单元测试·pytest
小熊出擊3 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
小熊出擊4 天前
【pytest】使用 marker 向 fixture 传递数据
python·pytest
wa的一声哭了4 天前
Deep Learning Optimizer | Adam、AdamW
人工智能·深度学习·神经网络·机器学习·自然语言处理·transformer·pytest
专职6 天前
pytest生成测试用例,allure生成测试报告
测试用例·pytest
小丁爱养花9 天前
接口自动化测试 - pytest [1]
python·自动化·pytest
向上的车轮10 天前
如何用AI工具开发一个轻量化CRM系统(七):AI生成pytest测试脚本
pytest