我创建了一个完全空的PyDev项目(不是“PyDev Django”,只是“PyDev”),里面有这个单独的文件:
import unittest
class Test(unittest.TestCase):
def testName(self):
print "hello world"
当我右键单击该文件并选择“Run As” - >“Python unit test”,或按CTRL + F9并单击“testName”时,我收到此错误:
Traceback (most recent call last):
File "C:\Program Files\Brainwy\LiClipse 1.2.0\plugins\org.python.pydev_3.8.0.201409251617\pysrc\runfiles.py", line 201, in <module>
main()
File "C:\Program Files\Brainwy\LiClipse 1.2.0\plugins\org.python.pydev_3.8.0.201409251617\pysrc\runfiles.py", line 26, in main
import pydev_runfiles
File "C:\Program Files\Brainwy\LiClipse 1.2.0\plugins\org.python.pydev_3.8.0.201409251617\pysrc\pydev_runfiles.py", line 5, in <module>
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 20, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
如果我把它放在文件中:
if __name__ == "__main__":
unittest.main()
并使用“Run As”执行它 - &gt;“Python Run”,它运行正常,但当然在文件中有很多测试的情况下会很不方便。
如何在不使用Django的情况下让PyDev执行单元测试?
答案 0 :(得分:0)
通过将LiClipse从1.2.0更新为1.4.0来解决:)