Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixture loading works with loaddata but fails silently in unit test in Django

I can load the fixture file in my django application by using loaddata:

manage.py loaddata palamut

The fixture palamut.yaml is in the directory palamut/fixtures/

I have a unit test module service_tests.py in palamut/tests/. Its content is here:

import unittest
from palamut.models import *
from palamut.service import *
from palamut.pforms import *

class ServiceTest(unittest.TestCase):
    fixtures = ['palamut.yaml']

    def test_convert_vensim(self):
        game_definition = GameDefinition.objects.get(pk=1)

This unit test gives the following error:

DoesNotExist: GameDefinition matching query does not exist.

I debugged the script, and found out that the fixture is not loaded in the unit test module.

Do you have any suggestions about the cause of this behavior?

By the way, test logs don't contain anything related to fixture loading.

like image 722
Mert Nuhoglu Avatar asked Jan 24 '23 03:01

Mert Nuhoglu


1 Answers

Your TestCase should be an instance of django.test.TestCase, not unittest.TestCase

like image 108
oggy Avatar answered Feb 22 '23 22:02

oggy