Models inside test folder - Django 1.7 problem

204 views
Skip to first unread message

galozek

unread,
Sep 4, 2014, 10:53:57 AM9/4/14
to django-d...@googlegroups.com
Hi,
I'm trying to port my project to Django 1.7. Every goes fine except 1 problem with an abstract model testing.
Django 1.7 runs migrate command while testing. That means models not included in migrations are omitted. That's the issue I've got.

What I do in my /app/tests/ directory:
  • I keep there a dummy model: class TestBaseImage(BaseImage): pass
  • All it does is to inherit from the abstract BaseImage model.
  • In my tests, when I try to create an instance of TestBaseImage I get DB error saying table does not exist
Is there any good way to make that work with new migration system? I don't want to include my dummy model in my migrations - that's obvious. I need a way to test that abstract model - it worked in Django 1.6 but with new migrations it doesn't.

Carl Meyer

unread,
Sep 4, 2014, 12:07:52 PM9/4/14
to django-d...@googlegroups.com
On 09/04/2014 08:53 AM, galozek wrote:
> I'm trying to port my project to Django 1.7. Every goes fine except 1
> problem with an abstract model testing.
> Django 1.7 runs migrate command while testing. That means models not
> included in migrations are omitted. That's the issue I've got.
>
> What I do in my /app/tests/ directory:
>
> * I keep there a dummy model: classTestBaseImage(BaseImage): pass
> * All it does is to inherit from the abstract *BaseImage* model.
> * In my tests, when I try to create an instance of TestBaseImage I get
> DB error saying *table does not exist*
>
> Is there any good way to make that work with new migration system? I
> don't want to include my dummy model in my migrations - that's obvious.
> I need a way to test that abstract model - it worked in Django 1.6 but
> with new migrations it doesn't.

Can you put the test model in its own models.py in a test-only "app",
and then include that test-only app in INSTALLED_APPS only when running
tests?

There is a long-time ticket requesting a cleaner way to do test-only
models: https://code.djangoproject.com/ticket/7835

The technique you were relying on wasn't documented and really only
worked by accident in previous Django versions.

Carl
Reply all
Reply to author
Forward
0 new messages