【测试】【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
相关推荐
慌糖1 天前
[特殊字符]️ 基于Pytest的自动化测试框架架构解析
pytest
旦莫2 天前
Pytest教程:为什么Pytest要用插件模式?
python·单元测试·自动化·pytest
三次握手四次挥手3 天前
基于Python+Pytest实现自动化测试(全栈实战指南)
开发语言·python·自动化·k8s·apache·pytest·代码规范
世界的尽头在哪里4 天前
python测试框架之pytest
开发语言·python·测试工具·单元测试·pytest
胆大的5 天前
怎样才能设计好的自动化测试用例
自动化·测试用例·pytest
雨中夜归人8 天前
自动化测试工具playwright中文文档-------14.Chrome 插件
python·测试工具·自动化·pytest·playwright
小马哥编程12 天前
【软件测试】自动化测试框架Pytest + Selenium的使用
selenium·测试工具·pytest
明月与玄武15 天前
Pytest多环境切换实战:测试框架配置的最佳实践!
pytest·pytest框架环境切换