【测试】【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
相关推荐
兴趣使然黄小黄7 小时前
【Pytest】Pytest框架快速入门
python·pytest
m0_632482501 天前
Jenkins + Pytest +allure接口自动化测试配置与操作
jenkins·集成测试·pytest·jenkins配置
李星星BruceL1 天前
Pytest第三章(参考指南1)
python·自动化·pytest
哎呀呦呵1 天前
pytest基本使用
python·pytest
Kristen_YXQDN1 天前
PyCharm 中 pytest 运行 python 测试文件报错:D:\Python_file\.venv\Scripts\python.exe: No module named pytest
运维·开发语言·python·pycharm·pytest
Low--Key1 天前
pytest框架快速入门
python·自动化·pytest
姜西西_1 天前
自动化测试框架pytest之fixture
android·java·pytest
测试开发Kevin1 天前
超级实用!汇总pytest中那些常用的参数
单元测试·pytest
Beaman10241 天前
pytest框架
python·pytest
昔时扬尘处2 天前
【Files Content Replace】文件夹文件内容批量替换自动化测试脚本
c语言·python·pytest·adi