运行Django测试用例允许您像这样指定详细程度(0,1,2,3)
manage.py test -v 2 myapp.tests.test_mycode.TestMyCode.test_func
如何在test_func
答案 0 :(得分:2)
您可以使用inspect
模块:
from django.test import TestCase
import inspect
class MyTest(TestCase):
def get_verbosity(self):
for s in reversed(inspect.stack()):
options = s[0].f_locals.get('options')
if isinstance(options, dict):
return int(options['verbosity'])
return 1
def test_func(self):
verbosity = self.get_verbosity()
self.assertEqual(verbosity, 2)