【测试】【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
python·测试工具·自动化·pytest
南部余额2 天前
playwright解决重复登录问题,通过pytest夹具自动读取storage_state用户状态信息
前端·爬虫·python·ui·pytest·pylawright
小码哥说测试5 天前
接口自动化进阶 —— Pytest全局配置pytest.ini文件详解!
自动化测试·软件测试·测试工具·自动化·pytest·测试工程师
天才测试猿6 天前
Python常用自动化测试框架—Pytest
自动化测试·软件测试·python·功能测试·测试工具·测试用例·pytest
Rhys..6 天前
2、pytest核心功能(进阶用法)
开发语言·python·pytest
一只天蝎的晋升之路7 天前
Python中常用的测试框架-pytest和unittest
开发语言·python·pytest
明月与玄武7 天前
pytest-xdist 进行高效并行自动化测试
pytest·pytest-xdist·进行高效并行自动化测试
测试笔记(自看)8 天前
Python+Requests+Pytest+YAML+Allure接口自动化框架
python·自动化·pytest·allure
活跃家族8 天前
Jsonpath使用
python·pytest
Rhys..8 天前
4、pytest常用插件
pytest