Ticket #520 (assigned defect)

Opened 5 years ago

Last modified 5 years ago

models defined in tests are not created by South

Reported by: joeri@… Owned by: andrew
Priority: major Milestone: The Future
Component: migrations Version: 0.7.1
Keywords: Cc:


Sometimes you want to test a new model in your unit tests. With Django, models defined in tests.py are created automatically (they are created by the regular syncdb when running the test command).

from django.test import TestCase
from django.db import models

from myproject.myapp.models import MyAbstractBaseModel

class MyTestModel(MyAbstractBaseModel):
    name = models.CharField(blank=False, max_length=100)

    class Meta:
        app_label = 'myapp'

class SimpleTests(TestCase):
    def test_my_test_model(self):

These models in tests.py usually need an app_label of an existing application to be picked up. However, when the application is under South, these test models are skipped by Django and not picked up by South either.

A simple work around for now is to set the app_label to use an application that is not under South, unless the app_label is actually important for your tests.

Change History

comment:1 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Milestone changed from 0.7.2 to The Future

This is a nice-to-have for now, so I'll put it as The Future. The recommended workaround in the meantime is, as you say, to put test models under a non-migrated app label.

Note: See TracTickets for help on using tickets.