【测试】【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
相关推荐
IT求学人1 天前
pytest运行用例的常见方式及参数
pytest
开源优测2 天前
什么是pytest.ini及如何在Pytest中应用以提升配置效率
pytest
摸鱼仙人~3 天前
ImportError: cannot import name ‘FixtureDef‘ from ‘pytest‘
conda·pytest·fastapi
唐古乌梁海3 天前
【pytest-jira】自动化用例结合jira初版集成思路
pytest·jira
小码哥说测试4 天前
高效执行自动化用例:分布式执行工具pytest-xdist实战!
自动化测试·软件测试·功能测试·jmeter·pytest·postman·测试工程师
予早5 天前
pytest asyncio 支持插件 pytest-asyncio
pytest
爱学测试的雨果7 天前
Pytest自动化测试框架关联/参数化实战
前端·pytest
测试杂货铺7 天前
Pytest快速入门
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest