Disabling migrations when running tests

825 views
Skip to first unread message

marcin....@gmail.com

unread,
Jul 16, 2016, 4:45:18 PM7/16/16
to Django users
Hi all.

Is possible to disable migrations execution when running tests?

Thanks,
Marcin

Ryan Castner

unread,
Jul 16, 2016, 5:57:18 PM7/16/16
to Django users
Could you explain what you mean by running tests? Migrations are executed when you run `./manage.py migrate`, if you are running `./manage.py test ...` it shouldn't be running your migrations, probably just gives a log warning that you have unapplied migrations. Here are the django docs on migrations

marcin....@gmail.com

unread,
Jul 16, 2016, 6:05:07 PM7/16/16
to Django users


On Saturday, July 16, 2016 at 11:57:18 PM UTC+2, Ryan Castner wrote:
Could you explain what you mean by running tests?

Yes. I'm talking about "manage.py test".

The docs says:
"New in Django 1.8 [...]  If the database does not exist, it will first be created. Any migrations will also be applied in order to keep it up to date."



I don't need automatically created test databases nor migrations applied. Can I disable this?

Marcin

James Schneider

unread,
Jul 16, 2016, 6:20:30 PM7/16/16
to django...@googlegroups.com

>>
>> Could you explain what you mean by running tests?
>
>
> Yes. I'm talking about "manage.py test".
>
> The docs says:
> "New in Django 1.8 [...]  If the database does not exist, it will first be created. Any migrations will also be applied in order to keep it up to date."
>
> Source: https://docs.djangoproject.com/en/1.9/topics/testing/overview/#the-test-database 
>
>
> I don't need automatically created test databases nor migrations applied. Can I disable this?
>

I don't know of a way to do so. You're probably better off using a separate test suite than relying on manage.py to handle the setup of the testing environment for you.

Out of curiosity, are you not testing anything database-related? I'm not sure how you expect your test suite to be valid if your database is not initialized correctly.

-James

Fabio C. Barrionuevo da Luz

unread,
Jul 16, 2016, 6:24:38 PM7/16/16
to django...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWH_QWWU1AadSup--haNKPMiJ48gB6Q-djX6zTH4xJf1g%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Fábio C. Barrionuevo da Luz
Palmas - Tocantins - Brasil - América do Sul


Blog colaborativo sobre Python e tecnologias Relacionadas, mantido totalmente no https://github.com/pythonclub/pythonclub.github.io .

Todos são livres para publicar. É só fazer fork, escrever sua postagem e mandar o pull-request. Leia mais sobre como publicar em README.md e contributing.md.
Regra básica de postagem:
"Você" acha interessante? É útil para "você"? Pode ser utilizado com Python ou é útil para quem usa Python? Está esperando o que? Publica logo, que estou louco para ler...

marcin....@gmail.com

unread,
Jul 16, 2016, 6:44:26 PM7/16/16
to Django users


On Sunday, July 17, 2016 at 12:20:30 AM UTC+2, James Schneider wrote:

>
> I don't need automatically created test databases nor migrations applied. Can I disable this?
>

I don't know of a way to do so. You're probably better off using a separate test suite than relying on manage.py to handle the setup of the testing environment for you. 

Out of curiosity, are you not testing anything database-related? I'm not sure how you expect your test suite to be valid if your database is not initialized correctly.


I'm using databases but they aren't initialized by Django. Of course tests must be run in Django environment. Test runner should handle transactions properly (i.e. start trn and rollback after finishing every test), but it should not touch anything in db. In that scenario flushing is not necessary and may be skipped for speed up.

On Sunday, July 17, 2016 at 12:24:38 AM UTC+2, Fabio Caritas Barrionuevo da Luz wrote:

 Thanks. I think it should be embedded within Django and should be configurable via settings.

Marcin

Tim Graham

unread,
Jul 16, 2016, 9:08:49 PM7/16/16
to Django users
You can use MIGRATION_MODULES for this: https://docs.djangoproject.com/en/1.9/ref/settings/#migration-modules

Also, there's a ticket to simplify disabling of migrations during tests further: https://code.djangoproject.com/ticket/25388

marcin....@gmail.com

unread,
Jul 17, 2016, 3:56:32 AM7/17/16
to Django users


On Sunday, July 17, 2016 at 3:08:49 AM UTC+2, Tim Graham wrote:
You can use MIGRATION_MODULES for this: https://docs.djangoproject.com/en/1.9/ref/settings/#migration-modules

Also, there's a ticket to simplify disabling of migrations during tests further: https://code.djangoproject.com/ticket/25388


Thanks. 

BTW: Would you consider bringing back patch https://github.com/django/django/commit/157d7f1f1de4705daddebb77f21bd7097a74513d ? This patch is what I've asking for months.

Marcin

Derek

unread,
Jul 17, 2016, 9:13:05 AM7/17/16
to Django users
I use a small "hack" which Works For Me :)

I use a shell script to run the tests (call it, for example, `tester.sh`) :-

mv myapp/fixtures myapp/_fixtures
python manage.py test --traverse-namespace tests --settings=test_settings
mv myapp/_fixtures myapp/fixtures

So; basically rename the fixtures directories - run the tests - and then restore the correct names.

HTH until we have an "official" patch.

Derek

unread,
Jul 17, 2016, 9:14:55 AM7/17/16
to Django users
Please ignore this!  My apologies - I read "fixtures" instead of "migrations".

Tim Graham

unread,
Jul 17, 2016, 3:13:24 PM7/17/16
to Django users
BTW: Would you consider bringing back patch https://github.com/django/django/commit/157d7f1f1de4705daddebb77f21bd7097a74513d ? This patch is what I've asking for months.

Marcin

Yes -- that patch didn't work properly as noted on the ticket. We'll certainly include a working patch if we have one.
Reply all
Reply to author
Forward
0 new messages