3

Since upgrading my Django project to Django 1.8 using the default Django test runner, I'm finding that my tests take between 10 and 15 seconds to start up because of the new default behavior of running migrations before tests. It now takes longer for my test suite to start up then it does to run the actual tests themselves. I only have seven models, none of which are that complex, and over 180 tests. I'm running my tests against a PostgreSQL 9.4.4. database on a 1.86 GHz Mac laptop with 4 GB of RAM. I found this question which said to create a settings_test.py file that contains a MIGRATION_MODULE setting and then specify that settings_test file when running your tests. Could someone explain further how to implement this solution? Is the settings_test file supposed to look like this if you have two apps?

MIGRATION_MODULES={'app1': 'app1.migrations_not_used_in_tests',
                   'app2': 'app2.migrations_not_used_in_tests'}

If that's true, how would you run your tests as described if you have multiple apps?

DJANGO_SETTINGS_MODULE='???.settings_test' python manage.py test

I tried creating the exact settings_test.py file that specified 'myapp' even though I don't have an app named 'myapp' and while my tests ran, the migrations also ran prior to the tests as I expected they would. I'm sorry if this seems like a dumb question but I'm relatively new to Django.

Thanks.

Community
  • 1
  • 1
Jim
  • 13,430
  • 26
  • 104
  • 155
  • You might try: https://pypi.python.org/pypi/django-test-without-migrations/ – Brandon Taylor Sep 21 '15 at 23:37
  • I tried that package but when I ran it I got this error: "manage.py: error: no such option: —nomigrations" – Jim Sep 21 '15 at 23:59
  • Is `test_without_migrations` listed before your local applications in `INSTALLED_APPS` ? – Brandon Taylor Sep 22 '15 at 00:23
  • At one point it was. In fact I put it at the very top of my INSTALLED_APPS list, even before Django's middleware. – Jim Sep 22 '15 at 01:02
  • You might reach out to the author at: https://github.com/henriquebastos/django-test-without-migrations – Brandon Taylor Sep 22 '15 at 01:23
  • (smile) Already did that. He suggested opening up an issue. Thanks Brandon for your suggestions. They are appreciated. – Jim Sep 22 '15 at 01:42
  • I've learned that you need to put 'test_without_migrations' *after* your Django apps but *before* all of your project apps in the INSTALLED_APPS setting in order for the "--nomigrations" flag to work. – Jim Sep 22 '15 at 17:02
  • I smell a pull request for updated docs coming :) – Brandon Taylor Sep 22 '15 at 17:07

0 Answers0