运行" 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
但我使用了与#34; 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")
答案 0 :(得分:3)
如果您正在使用迁移,则会加载您的initial_data.json after every migration。如果要在测试中加载夹具,请执行以下操作:
class ResumeTest(TestCase):
fixtures = ['my_data']
...
请参阅Official django documentation。
此外,将'initial_data.json'重命名为'my_data.json'以避免在每次迁移后加载它,这可能导致测试失败。