问题描述
版本号是Django 1.6,Python 3.3.2和Mac OS X 10.9我用这个命令创建一个应用程序$ /
python3 manage.py startapp列表
然后在我的列表/ tests.py文件中,我将这段代码
from django.test import TestCase
类SmokeTest(TestCase):
def test_bad_maths(self):
self.assertEqual(1 + 1,3)
然后我从应用程序根文件夹运行此命令
python3管理。 py test
这是回溯的堆栈跟踪,它不能正常工作
E
==================== b。(b)。。。。。。。。 $ b错误:test_bad_maths(lists.tests.SmokeTest)
---------------------------------- ------------------------------------
追溯(最近的最后一次呼叫):
文件/ usr / local / lib / python3。 3 / site-packages / django / db / backends / __ init__.py,第124行,在ensure_connection
self.connect()
文件/usr/local/lib/python3.3/site- package / django / db / backends / __ init__.py,第111行,连接
conn_params = self.get_connection_params()
文件/usr/local/lib/python3.3/site-packages/ django / db / backends / __ init__.py,第85行,get_connection_params
raise NotImplementedError
NotImplementedError
在处理上述异常时发生了另一个异常:
追溯(最近的最后一次调用):
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第653行,在supports_transactions
self.connection.enter_transaction_management()
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第288行,enter_transaction_management
如果被管理== self.get_autocommit():
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第324行,在get_autocommit
self.ensure_connection()
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第124行,确保_link
self.connect()
文件/usr/local/lib/python3.3/site-packages/django/db/utils.py,第86行,__exit__
db_exc_type = getattr(self.wrapper.Database,dj_exc_type .__ name__)
AttributeError:'DatabaseWrapper'对象没有属性'数据库'
在处理上述异常时发生另一个异常:
追溯(最近的最后一次调用):
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第124行,确保连接
self.connect()
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第111行,连接
conn_params = self.get_connection_params()
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第85行,get_connection_params
提高NotImplementedError
NotImplementedError
在处理上述异常时,发生另一个异常:
追溯(最近最近调用):
文件/ usr /local/lib/python3.3/site-packages/django/test/testcases.py,第178行,__call__
self._pre_setup()
文件/ usr / local / lib / python3 .3 / site-packages / django / test / testcases.py,第749行,在_pre_setup
self._fixture_setup()
文件/usr/local/lib/python3.3/site-packages /django/test/testcases.py,第861行,在_fixture_setup中
如果不是,则连接_support_transactions():
文件/usr/local/lib/python3.3/site-packages/django/test/ testcases.py,第848行,在connections_support_transactions
中为conn.all())
文件/usr/local/lib/python3.3/site-packages/django/test/testcases。 py,第848行,< genexpr>
在conn.all())
文件/usr/local/lib/python3.3/site-packages/django/utils/functional.py,第49行,__get__
res = instance .__ dict __ [self.func .__ name__] = self.func(instance)
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__。 py,行664,在supports_transactions
self.connection.leave_transaction_management()
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py ,line 317,in leave_transaction_management
if managed == self.get_autocommit():
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py ,line 324,in get_autocommit
self.ensure_connection()
文件/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py,第124行,在ensure_connection
self.connect()
文件/usr/local/lib/python3.3/site-packages/django/db/utils.py,第86行,__exit__
db_exc_type = getattr(self.wrapper.Database, dj_exc_type .__ name__)
AttributeError:'DatabaseWrapper'对象没有属性'数据库'
---------------------- ------------------------------------------------
Ran 0测试在0.031s
FAILED(errors = 1)
我有完全相同的环境:
* Mac OS X 10.9
* Python 3.3.2
* Django 1.6
我已经安装了virtualenv 1.10.1并创建了一个,安装django并创建了项目和应用程序:
virtualenv-3.3 tt
cd tt
。 bin / activate
pip install django == 1.6
django-admin.py startproject myproj
cd myproj
chmod + x manage.py
./manage.py startapp列出
现在我将代码粘贴到列表/ test.py中,并使用默认设置运行测试。 py(数据库sqlite3等)
./ manage.py test
/ pre>
并获得正确的结果:
为别名默认创建测试数据库...
F
==================== b。(b)。。。。。。。。 $ b FAIL:test_bad_maths(lists.tests.SmokeTest)
---------------------------------- ------------------------------------
追溯(最近的最后一次呼叫):
文件/Users/erevilla/tt/myproj/lists/tests.py,第6行,在test_bad_maths
self.assertEqual(1 + 1,3)
AssertionError:2!= 3
------------------------------------------- ---------------------------
以0.001s $为单位进行1次测试b
$ b FAILED(failures = 1)
销毁别名为default的测试数据库...
我无法重现您的问题。请检查:
- settings.py(您正在使用什么数据库)
- manage.py(不正确的版本)
- DJANGO_SETTINGS_MODULE未定义
Version numbers are Django 1.6, Python 3.3.2 and Mac OS X 10.9
I create an app with this command
python3 manage.py startapp lists
Then in my lists/tests.py file I put this code
from django.test import TestCase
class SmokeTest(TestCase):
def test_bad_maths(self):
self.assertEqual(1 + 1, 3)
then I run this command from the app root folder
python3 manage.py test
and this is the stack trace that comes back, it's not working correctly
E
======================================================================
ERROR: test_bad_maths (lists.tests.SmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 111, in connect
conn_params = self.get_connection_params()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 85, in get_connection_params
raise NotImplementedError
NotImplementedError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 653, in supports_transactions
self.connection.enter_transaction_management()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 288, in enter_transaction_management
if managed == self.get_autocommit():
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
self.ensure_connection()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 86, in __exit__
db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 111, in connect
conn_params = self.get_connection_params()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 85, in get_connection_params
raise NotImplementedError
NotImplementedError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 178, in __call__
self._pre_setup()
File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 749, in _pre_setup
self._fixture_setup()
File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 861, in _fixture_setup
if not connections_support_transactions():
File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 848, in connections_support_transactions
for conn in connections.all())
File "/usr/local/lib/python3.3/site-packages/django/test/testcases.py", line 848, in <genexpr>
for conn in connections.all())
File "/usr/local/lib/python3.3/site-packages/django/utils/functional.py", line 49, in __get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 664, in supports_transactions
self.connection.leave_transaction_management()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 317, in leave_transaction_management
if managed == self.get_autocommit():
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 324, in get_autocommit
self.ensure_connection()
File "/usr/local/lib/python3.3/site-packages/django/db/backends/__init__.py", line 124, in ensure_connection
self.connect()
File "/usr/local/lib/python3.3/site-packages/django/db/utils.py", line 86, in __exit__
db_exc_type = getattr(self.wrapper.Database, dj_exc_type.__name__)
AttributeError: 'DatabaseWrapper' object has no attribute 'Database'
----------------------------------------------------------------------
Ran 0 tests in 0.031s
FAILED (errors=1)
I have exact the same environment: * Mac OS X 10.9 * Python 3.3.2 * Django 1.6
I have virtualenv 1.10.1 installed and create one, install django and create the project and app:
virtualenv-3.3 tt
cd tt
. bin/activate
pip install django==1.6
django-admin.py startproject myproj
cd myproj
chmod +x manage.py
./manage.py startapp lists
Now I pasted your code into lists/test.py and run the test with the default settings.py (database sqlite3, etc.)
./manage.py test
and got the right results:
Creating test database for alias 'default'...
F
======================================================================
FAIL: test_bad_maths (lists.tests.SmokeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/erevilla/tt/myproj/lists/tests.py", line 6, in test_bad_maths
self.assertEqual(1 + 1, 3)
AssertionError: 2 != 3
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (failures=1)
Destroying test database for alias 'default'...
I can't reproduce your problem. Please check:
- settings.py (what database are you using)
- manage.py (for incorrect version)
- DJANGO_SETTINGS_MODULE is undefined
这篇关于AttributeError:'DatabaseWrapper'对象没有属性'数据库'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!