I am trying to test my Django test files separately, one by one, as ./manage.py test
freezes for 5secs after each run due to heavy apps.
This is my test (not even a test yet though, just playing with requests):
if __name__ == "__main__":
import unittest
# manually get all the django stuff into memory if file is called directly
import os,sys
TEST_ROOT = os.path.realpath(os.path.dirname(__file__))
PROJ_AND_TEST_ROOT = os.path.dirname(os.path.dirname(TEST_ROOT))
PROJECT_ROOT = os.path.join(PROJ_AND_TEST_ROOT, 'the_game')
sys.path.append(PROJECT_ROOT)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "the_game.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
from django.test import TestCase, RequestFactory
from django.contrib.auth.models import User
from interface.views import bets
class ViewTests(TestCase):
def test_bets_view(self):
request_factory=RequestFactory()
request=request_factory.get('/')
user = User.objects.create_user('testname','test@na.me','testname')
request.user=user
response=bets(request)
print response
if __name__ == "__main__":
unittest.main()
However, running this I get the following:
======================================================================
ERROR: test_bets_view (__main__.ViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/test/testcases.py", line 182, in __call__
self._pre_setup()
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/test/testcases.py", line 754, in _pre_setup
self._fixture_setup()
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/test/testcases.py", line 887, in _fixture_setup
if not connections_support_transactions():
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/test/testcases.py", line 874, in connections_support_transactions
for conn in connections.all())
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/test/testcases.py", line 874, in <genexpr>
for conn in connections.all())
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/utils/functional.py", line 55, in __get__
res = instance.__dict__[self.func.__name__] = self.func(instance)
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/db/backends/__init__.py", line 782, in supports_transactions
self.connection.leave_transaction_management()
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/db/backends/__init__.py", line 338, in leave_transaction_management
if managed == self.get_autocommit():
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/db/backends/__init__.py", line 345, in get_autocommit
self.ensure_connection()
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection
self.connect()
File "/Users/1111/.virtualenvs/the_game/lib/python2.7/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'
The project itself works perfectly without errors (./manage.py runserver
), as do django tests (./manage.py test ../tests
).
How can I fix this?
Aucun commentaire:
Enregistrer un commentaire