Opened 5 years ago

Closed 5 years ago

#14339 closed (duplicate)

Enable testing when you can't create/destroy databases

Reported by: Martin Omander <martin.omander@…> Owned by: nobody
Component: Testing framework Version: 1.2
Severity: Keywords: test database
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When you are using Django in a hosted environment, you don't always have privileges to "CREATE DATABASE" or "DROP DATABASE". Some services allow you to create and destroy databases, but only through a web UI and not from Python code. In either case, you can't run Django unit tests. Developers using Webfaction, like myself, are in this situation. See this forum thread for developers struggling with this problem.

I hacked my local _create_test_db() and _destroy_test_db() so they assume the test database exists and create and drop tables, instead of the entire database. This allows me to run unit tests, but at the cost of forking the Django code. If there was a new test runner that did the same thing, others who are on hosting services like Webfaction would be able to do testing without having to invent dirty hacks like I did. This new test runner would need to call new code in django/db/backends/ that drops all tables in a database.

Is a new test runner the right approach to solve this problem? Are there other approaches? Would this warrant a new method in to drop all tables in a database?

Change History (4)

comment:1 Changed 5 years ago by lukeplant

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Just to collect some related things which we might need to think about at the same time:

(BTW, With webfaction are you sure you can't create a DB using the XML-RPC api? )

comment:2 Changed 5 years ago by Martin Omander <martin.omander@…>

Thanks for the pointer to Webfaction's XML-RPC API! I tried the API and it works well, but I was not able to write a working test runner that calls it. I guess I don't understand the ins and outs of test runners and db connections well enough, so I'm back to hacking _create_test_db() and _destroy_test_db().

comment:3 Changed 5 years ago by ramiro

The Oracle backend has the 'TEST_CREATE' (and a 'TEST_USER_CREATE') boolean var that allows control of the DB (actually tablespace) creation process. Maybe we could extend/generalize this to the other backends somehow?

comment:4 Changed 5 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

Closing as a duplicate of #14296, since the solution is essentially the same.

Note: See TracTickets for help on using tickets.
Back to Top