Why Django-1.3 does not find my devices for UnitTest?

I am trying to use my instruments in UnitTest.

AddFavoritesTestCase(unittest.TestCase):  

fixtures = ['/Users/Bryan/work/osqa/fixtures/fixture_questions.json']  

def setUp(self):  
    self.factory = RequestFactory()  

def testAdminCanFavorite(self):  
    user = User.objects.get(pk=3)   
    ...  
    self.assertEqual(response.status_code, 200)  


======================================================================  
ERROR: testAdminCanFavorite (forum.tests.tests_building_stickyness.AddFavoritesTestCase)  
----------------------------------------------------------------------  
Traceback (most recent call last):  
  File "/Users/Bryan/work/osqa/forum/tests/tests_building_stickyness.py", line 18, in testAdminCanFavorite  
    user = User.objects.get(pk=3) # Kallie has admin  
  File "/usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/db/models/manager.py", line 132, in get  
    return self.get_query_set().get(*args, **kwargs)  
  File "/Users/Bryan/work/osqa/forum/models/base.py", line 64, in get  
    obj = super(CachedQuerySet, self).get(*args, **kwargs)  
  File "/usr/local/lib/python2.7/site-packages/Django-1.3-py2.7.egg/django/db/models/query.py", line 349, in get  
    % self.model._meta.object_name)  
DoesNotExist: User matching query does not exist.  

Appliances seem to not load.

I was able to use the fixtures to populate the database, but for some reason the fixtures are not in tests.

The path is right, but I can’t understand what is happening.

$ ls /Users/Bryan/work/osqa/fixtures/fixture_questions.json 
/Users/Bryan/work/osqa/fixtures/fixture_questions.json

Performing a test with higher granularity indicates that no devices were found. I am running Django 1.3.

+3
source share
2 answers

Import TestCase from django.test;

  • Not: import unittest
  • Not: import django.utils.unittest
  • But: import django.test

Like this:

from django.test import TestCase

class test_something(TestCase):
    fixtures = ['one.json', 'two.json']
    ...

https://docs.djangoproject.com/en/1.3/topics/testing/#django.test.TestCase

+3
source

You do not pass the full path to the device, just the name of the device:

fixtures = ['fixture_questions.json']  

fixtures , INSTALLED_APPS, Django .

0

All Articles