【问题标题】:pytest reports too much on assert failurespytest 对断言失败的报告太多
【发布时间】:2019-06-11 10:59:36
【问题描述】:

有没有办法让pytest只输出一行断言错误?

当你有带有断言的模块时会出现这个问题,如果这些断言失败,它会转储失败的整个函数。

> assert r.status_code == 200, f"{idtest.tools.now()} wrong status code {r.status_code}: resp:{r.text}"
E AssertionError: 2019-06-11 12:41:17.239128 wrong status code 500: resp:{"timestamp":"2019-06-11T10:41:17.187+0000","status":500,"error":"Internal Server Error","message":"The user was not found","path":"/mid/business"}

在这种情况下,idtest.testapi.midbusiness() 完全显示在 pytest 输出中。

【问题讨论】:

  • pytest --tb={auto,long,short,line,native,no}。例如。 pytest --tb=no 根本不会打印任何痕迹。
  • @hoefling, --tb=short 给了我想要的东西

标签: python pytest verbosity


【解决方案1】:

调整回溯打印模式(--tb):

$ pytest --help
  --tb=style            traceback print mode (auto/long/short/line/native/no).

例如pytest --tb=no 根本不会打印任何痕迹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多