运行 Django 测试用例允许您像这样指定详细程度 (0,1,2,3)
manage.py test -v 2 myapp.tests.test_mycode.TestMyCode.test_func
如何在我的
test_func
中接收详细标志
最佳答案
您可以使用 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)
关于django - 如何在 Django 的测试中使用详细级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27456881/