根据文档,我可以在调用时设置 python 单元测试的详细级别unittest.main
, e.g.
unittest.main(verbosity=2)
我怎样才能在一段时间内访问这些信息unittest.TestCase
?
任何基于修补或子类化的方法都存在问题unittest.TestProgram
是你必须先把补丁安装到位unittest.TestProgram
已开始。但是,如果您的测试用例是通过发现运行的,那么这是不可能的:
python -m unittest discover -v
在发现案例中有效的方法是使用inspect https://docs.python.org/3/library/inspect.html模块在堆栈中搜索,直到方法出现unittest.TestProgram
发现:
import inspect
import unittest
def unittest_verbosity():
"""Return the verbosity setting of the currently running unittest
program, or 0 if none is running.
"""
frame = inspect.currentframe()
while frame:
self = frame.f_locals.get('self')
if isinstance(self, unittest.TestProgram):
return self.verbosity
frame = frame.f_back
return 0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)