【测试】【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
相关推荐
思则变3 天前
[Pytest][Part 1]Pytest 自动化测试框架
pytest
思则变4 天前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
思则变5 天前
[Pytest][Part 3]检测python package状态
pytest
cooldream200919 天前
pytest 框架详解与实战指南
pytest·测试
慕城南风19 天前
【pytest进阶】Pytest之conftest详解
pytest
编程小白gogogo20 天前
AI自动化测试速成(Pytest框架)
pytest
慕城南风20 天前
【pytest进阶】pytest详解及进阶使用
linux·服务器·pytest
Tom Boom1 个月前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest
不要一直敲门1 个月前
初学 pytest 记录
pytest