【测试】【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
相关推荐
彩色面团儿2 天前
Pytest框架测试用例分析(测试笔记二)
笔记·测试用例·pytest
阿蔹2 天前
Python-Pytest-Requests-API接口测试自动化框架2
python·自动化·pytest
彩色面团儿3 天前
Pycharm部署pytest运行测试(测试笔记一)
python·pycharm·集成测试·pytest
阿蔹4 天前
Python-Pytest
python·自动化·pytest
阿蔹4 天前
Python-Pytest-Requests-API接口测试自动化框架
python·自动化·pytest
先做个垃圾出来………4 天前
pytest + pytest-mock + pytest-parametrize为基础构建测试框架
microsoft·pytest
唐古乌梁海8 天前
【pytest】pytest详解-入门到精通
开发语言·python·pytest
我的xiaodoujiao10 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 36--二次封装MySQL数据库连接操作
python·学习·测试工具·pytest