我已经创建了一个项目来找出适合我的其他python项目的项目结构。
我真正想做的是进行一些测试。
example.py看起来像这样
import unittest
from A.A import A
__author__ = 'michael'
class ExampleTest(unittest.TestCase):
def setUp(self):
self.a = A()
pass
def test_stub(self):
self.assertEquals(self.a.foo(), 'foo')
if __name__ == '__main__':
unittest.main()
当我跑步时
/Temp $ nosetests
我得到django例外。
Traceback (most recent call last):
File "/usr/local/bin/nosetests", line 9, in <module>
load_entry_point('nose==1.3.0', 'console_scripts', 'nosetests')()
File "/usr/local/lib/python2.7/dist-packages/nose/core.py", line 118, in __init__
**extra_args)
File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
self.parseArgs(argv)
File "/usr/local/lib/python2.7/dist-packages/nose/core.py", line 135, in parseArgs
self.config.configure(argv, doc=self.usage())
File "/usr/local/lib/python2.7/dist-packages/nose/config.py", line 344, in configure
self.plugins.configure(options, self)
File "/usr/local/lib/python2.7/dist-packages/nose/plugins/manager.py", line 284, in configure
cfg(options, config)
File "/usr/local/lib/python2.7/dist-packages/nose/plugins/manager.py", line 99, in __call__
return self.call(*arg, **kw)
File "/usr/local/lib/python2.7/dist-packages/nose/plugins/manager.py", line 167, in simple
result = meth(*arg, **kw)
File "/usr/local/lib/python2.7/dist-packages/queries/nose_plugin.py", line 22, in configure
connection.use_debug_cursor = True
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 37, in __setattr__
return setattr(connections[DEFAULT_DB_ALIAS], name, value)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 196, in __getitem__
self.ensure_defaults(alias)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 170, in ensure_defaults
conn = self.databases[alias]
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 153, in databases
self._databases = settings.DATABASES
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
我根本得不到它。 django与它有什么关系?
EDIT1:
无法显示代码,因为我已经学会了如何使用unittest运行测试并删除了这个项目。
但我向你保证,A的代码只是关于使用B.像
这样的东西A类(): def __init(self): self.b = B()
def foo(self): b.foo()
B只是一个带有foo方法的类,它打印字符串'foo'。
答案 0 :(得分:0)
从第
行开始File "/usr/local/lib/python2.7/dist-packages/queries/nose_plugin.py", line 22, in configure
connection.use_debug_cursor = True
好像你已经安装了django-dynamic-fixture。这个包安装了一个使用django ORM的nose_plugin。