我使用的是 Django==1.7.11、mysql、python 2.7。
在我的设置文件中,我将 debug 设置为 True,我通过输入 django shell 确认了这一点,并且始终得到 True
.
>>> from django.conf import settings
>>> settings.DEBUG
True
但是在我的 tests.py
中文件:
import unittest
from django.conf import settings
import settings as settingsfile
from django.test import LiveServerTestCase
class SeleniumTest(LiveServerTestCase):
def test_nothing(self):
print 'File DEBUG is: %s' % (settingsfile.DEBUG, )
print 'Django DEBUG is: %s' % (settings.DEBUG, )
if __name__ == '__main__':
unittest.main()
>>>> File DEBUG is: True
>>>> Django DEBUG is: False
是否还有其他地方可能会更改 DEBUG 的值或在我不知道的测试文件中误用导入设置?
==更新==
这个link提到LiveServerTestCase
力量DEBUG=False
这样它就可以模仿生产服务器,但我更改了文件以使用 Django 的正常 TestCase
并最终得到相同的结果。
导入单元测试
from django.conf import settings
from django.test import TestCase
import settings as settingsfile
class SeleniumTest(TestCase):
def test_nothing(self):
print 'File DEBUG is: %s' % (settingsfile.DEBUG, )
print 'Django DEBUG is: %s' % (settings.DEBUG, )
if __name__ == '__main__':
unittest.main()
>>>> File DEBUG is: True
>>>> Django DEBUG is: False
最佳答案
Django 的测试以 DEBUG=False 运行。
https://docs.djangoproject.com/en/dev/topics/testing/overview/#other-test-conditions
关于python - 无论设置为 True,settings.DEBUG 仍然为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37530528/