4

I want to speed up my tests by running only necessary migrations to build database. Currently, Django runs all of them.

I know how to specify dependencies among migrations and actively use it. I watch for dependencies, most of my tests don't depend even on Django. I want some dividends for that.

Is there any way to specify particular apps or migrations on which test depends?

I found available_apps property of TransactionTestCase, which is marked as private API, but it doesn't work for me. Even if I run single test class or test method.

George Sovetov
  • 4,942
  • 5
  • 36
  • 57
  • 2
    You might find the [`--keepdb`](https://docs.djangoproject.com/en/1.9/ref/django-admin/#cmdoption-test--keepdb) option useful, to prevent Django from recreating the database and running the migrations each time you run the tests. – Alasdair Apr 26 '16 at 14:35
  • @Alasdair Yes, I know this option but it's still not exactly what I'm looking for. – George Sovetov Apr 26 '16 at 14:36
  • But what the use? if you don't want to use --keepdb you will spend a lot of time and effort to save a few seconds. – e4c5 Apr 26 '16 at 14:51
  • 2
    I don't want to depend on anything else. Migrations from other apps written by other developers may fail. I may use in-memory SQLite db. There may be a lot of reasons. Why is it effort? `python manage.py migrate myapp` works perfectly and install only specific dependencies. I expect same for tests. – George Sovetov Apr 26 '16 at 15:02
  • @GeorgeSovetov I am currently facing the same issue. Have you figured out how to apply migrations only for the specific app during the test? – Karen Jul 18 '23 at 07:14

0 Answers0