Enable testing when you can't create/destroy databases
|Reported by:||Martin Omander <martin.omander@…>||Owned by:||nobody|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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/creation.py 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 creation.py 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