【测试】【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
相关推荐
cendy-LL13 小时前
自动化测试之Pytest框架
pytest
我的xiaodoujiao19 小时前
API 接口自动化测试详细图文教程学习系列7--相关Python基础知识6
python·学习·测试工具·pytest
忘忧记21 小时前
pytest + YAML + requests`简单实例化
网络·pytest
我的xiaodoujiao1 天前
API 接口自动化测试详细图文教程学习系列8--测试接口
python·学习·测试工具·pytest
鹿鸣悠悠3 天前
pytest + requests + allure 接口自动化测试框架指南
pytest
忘忧记3 天前
pytest进阶参数化用法
前端·python·pytest
bug_rabbit3 天前
pytest-html 中文乱码问题终极解决方案(Windows版)
windows·html·pytest
庄小法3 天前
pytest
开发语言·python·pytest
工具人55554 天前
pytest练习
pytest
好家伙VCC4 天前
# Pytest发散创新:从基础测试到智能断言的实战进阶指南在现代软
java·python·pytest