3

Strange error after running "python manage.py test"

django.db.utils.OperationalError: Problem installing fixture 
'/home/voxa/django/test_test/resume/fixtures/initial_data.json': Could not load 
resume.Person(pk=1): no such table: resume_person

But i've used the same fixtures with "python manage.py loaddata initial_data.json"

UPD:

tests.py

from django.test import TestCase
from django.test import Client

from resume.models import Person

class ResumeTest(TestCase):

    def test_model(self):
        bio = Person(first_name="Homer", last_name="Simpson", birth_date="04.02.1978", email="mail@gmail.com", jabber="jabber@jabbim.com", skype="skype", other_contacts="tel: +380975322155", bio="Was born...")

    def test_index(self):
        client = Client()
        response = client.get('/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Volodymyr")
Community
  • 1
  • 1
Crampus
  • 491
  • 1
  • 8
  • 16

1 Answers1

5

If you're using migrations, your initial_data.json is loaded after every migration. If you want to load a fixture in your tests, do this:

class ResumeTest(TestCase):
    fixtures = ['my_data']
    ...

See Official django documentation.

Additionally, rename your 'initial_data.json' to 'my_data.json' to avoid it being loaded after every migration, which is what is probably causing your tests to fail.

Andriy Ivaneyko
  • 20,639
  • 6
  • 60
  • 82
dukebody
  • 7,025
  • 3
  • 36
  • 61
  • nothing changed after adding this line. As we can see django can see fixtures, but cant download it in some reasons "Problem installing fixture'/home/voxa/django/test_test/resume/fixtures/initial_data.json'" – Crampus Oct 27 '14 at 12:01
  • Change the name of the file of that fixture to something else, like mydata.json. – dukebody Oct 27 '14 at 12:11