Test, RunPython, Datamigrations with Django 1.7.5

29 views
Skip to first unread message

sam

unread,
Mar 4, 2015, 12:24:34 PM3/4/15
to django...@googlegroups.com
Hello,

I have an issue trying to run tests.
My application use a migration to have default fixtures (created using migrations.RunPython from a migration file).
The problem is when I launch manage.py test, the fixtures from the migration are created on the "production" database and not on the test_* database.

Is there a way to solve this issue ? Is this a known issue or nobody has this problem ?

Here is the migration

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


def create_bars(apps, schema_editor):
    Bar = apps.get_model("foo", "Bar")
    db_alias = schema_editor.connection.alias
   
Bar.objects.using(db_alias).bulk_create([
       
Bar(label="AAA"),
       
Bar(label="BBB")
    ])

class Migration(migrations.Migration):

    dependencies = [
        ('
foo', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(
create_bars),
    ]


Thanks

sam

unread,
Mar 4, 2015, 4:54:14 PM3/4/15
to django...@googlegroups.com
Well, answer is here: https://docs.djangoproject.com/en/1.7/topics/testing/overview/#rollback-emulation
Need to use serialized_rollback = True in TransactionTestCase
Reply all
Reply to author
Forward
0 new messages