【测试】【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
相关推荐
H_unique15 小时前
博客接口自动化测试--搭建测试环境&库的介绍&安装allure
python·pytest·测试
真智AI16 小时前
MCP+pytest自动重构回归:复刻ARIS循环
重构·pytest
零基础的修炼1 天前
自动化测试---pytest
pytest
鲜于言悠9052 天前
博客系统测试报告
python·功能测试·selenium·jmeter·测试用例·集成测试·pytest
0和1的舞者3 天前
高并发论坛系统:单元测试 + 接口自动化 + 性能测试 + CI/CD 全链路测试报告
java·测试开发·测试工具·jmeter·pytest·测试·测试报告
独断万古他化3 天前
Python+Pytest 搭建博客系统接口自动化测试框架(全用例执行+完整代码)
pytest·接口自动化·测试·allure·requests
王夏奇3 天前
python-pytest学习
python·学习·pytest
独断万古他化5 天前
Python 接口测试之 requests 库核心用法
python·pytest·接口测试·requests
姚青&5 天前
Pytest 测试用例生命周期管理-fixture
测试用例·pytest
姚青&18 天前
PyCharm 配置与界面化运行
pytest