5

I'm running a project on Django 1.8.12 and I'd like to preserve test database between runs as described in the documentation. Even though the test command itself lists the -k/--keepdb option in help text, using it fails:

vagrant@vagrant /vagrant/project (master) $ python manage.py test -k myapp.tests.testcase
nosetests myapp.tests.testcase -k --verbosity=1
Usage: manage.py [options]

manage.py: error: no such option: -k

vagrant@vagrant /vagrant/project (master) $ python manage.py test --keepdb myapp.tests.testcase
nosetests myapp.tests.testcase --keepdb --verbosity=1
Usage: manage.py [options]

manage.py: error: no such option: --keepdb

Calling the same command with some other options, e.g. -q or --failfast works fine. On the other hand, some other listed options such as --no-color fail in a similar manner.

Am I missing something here? How can I pass these options to the command?

Antti Mäki
  • 108
  • 1
  • 8
  • Are you using `django.test.TestCase` in the tests, or `unittest.TestCase`? – C14L Apr 06 '16 at 08:29
  • I'm using `django.test.TestCase`, but I don't think it matters much since they most likely never get called, the error terminates the execution before that. Switching to `unittest.TestCase` or defining `class TestCase(object): pass` causes the same error message when `-k` option is used. – Antti Mäki Apr 06 '16 at 09:13
  • Can you run tests in other apps, or do they fail too? The [Django 1.8 source](https://github.com/django/django/blob/1.8.12/django/test/runner.py#L55) does know it. – C14L Apr 06 '16 at 11:31
  • I do get the same error when trying to run tests in other apps within the same Django project. – Antti Mäki Apr 06 '16 at 12:21

1 Answers1

5

I had a similar problem, and issue was having the TEST_RUNNER set to django_nose in the project settings. So in ../settings/local.py, commenting out or removing this:

TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

allows the --keepdb switch to be used.

JessieinAg
  • 355
  • 3
  • 10
  • Indeed, --keepdb seems to be an option for Django's default testrunner. I however prefer to use NoseTests, so running the tests with `REUSE_DB=1 python manage.py test` does the trick for me. Marking the answer as correct since it helped me to find a solution that was suitable for me. – Antti Mäki Nov 14 '16 at 13:58
  • 1
    More recent versions of `django_nose` pass through the `--keepdb` options, so another solution is to upgrade that Python package (e.g. for me, upgrading `django-nose` from 1.4.1 to 1.4.4 allowed `--keepdb` to work) – Mark Longair Jul 31 '17 at 12:49