简体   繁体   English

如何在Python unittest中进行测试才能访问详细级别?

[英]How can a test in Python unittest get access to the verbosity level?

When calling a test suite in the Python unittest framework, it is possible to give a -v for higher level of verbosity, like: 在Python unittest框架中调用测试套件时,可以为-v提供更高级别的详细程度,例如:

python3 test_suite.py -v

How can a test case get access to the verbosity level ? 测试用例如何访问详细级别?

The verbosity isn't directly passed to TestCase or TestSuite since none of them actually need it for something. 详细程度不会直接传递给TestCaseTestSuite因为它们实际上都不需要它。 The runner uses the verbosity information (the class running your tests) to handle the amount of information printed out. runner使用冗长的信息 (类运行测试)来处理的信息打印出来的金额。

Looking at the source, since argv isn't cleared at any point, a non-intrusive way to check for the presense of the verbose flag would be to peek into argv and see if '-v' is inside it. 查看源代码,因为argv在任何时候都没有被清除,所以检查详细标志的presense的非侵入式方法是查看argv并查看是否在其中包含'-v'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM