62

I'm currently trying to automate Django tests using Hudson CI, and am struggling to find an option that will automatically destroy the test database if it already exists (typically it will ask for confirmation to destroy it, which the automatic testing obviously cannot provide for).

Any suggestions would be much appreciated!

Cheers, R

abdusco
  • 9,700
  • 2
  • 27
  • 44
Ric W
  • 2,232
  • 2
  • 18
  • 12
  • 2
    Ah. that did it! Where in earth is that documented? – Ric W Aug 24 '12 at 16:53
  • 1
    Answered that in an answer, so that you can close the question (which will save time to others who spend time lurking SO to find open questions) – jpic Aug 24 '12 at 16:55

1 Answers1

106

Use --help to see the docs of the test command:

>>> ./manage.py test --help   
Usage: ./manage.py test [options] [appname ...]

Runs the test suite for the specified applications, or the entire site if no apps are specified.

[...]

--noinput             Tells Django to NOT prompt the user for input of any
                      kind.

And use --noinput which defaults to destroying the test db;)

jpic
  • 32,891
  • 5
  • 112
  • 113
  • 4
    ... and you know, what I did? I patched Django, manually, every single time, setting 'autoclobber' to True. THANKS. This should be documented somewhere in Django docs, if it is not already. – dotz Oct 12 '14 at 13:42
  • 3
    "This should be documented somewhere..." -- it seems that it is documented now, but only HERE. – Mark Chackerian Aug 07 '17 at 14:15
  • 4
    Also, apparently undocumented is the fact that `--noinput` works with testserver command, e.g. `manage.py testserver --noinput my_fixture.json` – Mark Chackerian May 14 '18 at 16:50
  • 1
    It is now documented (at this time in the dev documentation). https://docs.djangoproject.com/en/dev/topics/testing/overview/ – SGaist Mar 11 '19 at 14:11