在运行 Python 单元测试套件时,您可以传递哪些数字作为详细信息? [英] What numbers can you pass as verbosity in running Python Unit Test Suites?

查看:25
本文介绍了在运行 Python 单元测试套件时,您可以传递哪些数字作为详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python unittest 框架有一个冗长的概念,我似乎在任何地方都找不到定义.例如,我正在运行这样的测试用例(就像在文档中):

The Python unittest framework has a concept of verbosity that I can't seem to find defined anywhere. For instance, I'm running test cases like this (like in the documentation):

suite = unittest.TestLoader().loadTestsFromTestCase(MyAwesomeTest)
unittest.TextTestRunner(verbosity=2).run(suite)

我见过的唯一一个通过冗长的数字是 2.这个神奇的数字是什么,它是什么意思,我还能通过什么?

The only number I've ever seen passed as verbosity is 2. What is this magic number, what does it mean, what what else can I pass?

推荐答案

你只有 3 个不同的级别:

You only have 3 different levels:

  • 0 (安静):您只需获得执行的测试总数和全局结果
  • 1 (默认):每次成功测试都会得到相同的加点或每次失败都会得到 F
  • 2 (verbose):你得到每个测试的帮助字符串和结果

您可以使用命令行参数而不是详细参数:--quiet--verbose,它们的作用类似于将 0 或 2 传递给跑步者.

You can use command line args rather than the verbosity argument: --quiet and --verbose which would do something similar to passing 0 or 2 to the runner.

这篇关于在运行 Python 单元测试套件时,您可以传递哪些数字作为详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆