#12373 closed (wontfix)
Add keepdb option to test command
Reported by: | Phui Hock | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Allow user to keep the test database after running all the test cases for later inspection.
Attachments (1)
Change History (4)
by , 15 years ago
Attachment: | keepdb.diff added |
---|
follow-up: 2 comment:1 by , 15 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 15 years ago
Would you be kind enough to point me to the right direction where the test database is flushed at the start of each test?
AFAIK, the only time the test db is flushed is when all tests are run, in django.test.simple.run_tests(). I commented os.remove(test_database_name)
from django/db/backends/sqlite3/creation.py and ran the unit tests (manage.py test auth sites sessions). All test data are retained in the test db.
I reckon that test data should be setup in a way that is independent of the previous tests. I find it useful to inspect the test db as part of the debug process when test cases fail.
comment:3 by , 15 years ago
Each test *is* independent and starts with a clean database, which is exactly why --keepdb won't work. *All* the test data isn't retained in the test db - only the test data *from the last executed test* is retained, unless you're running doctests or standard unit tests, in which case it gets really messy to determine exactly what will be in the database at the end of the test run.
As for the code that does this: you're looking for TransactionTestCase._fixture_setup() and TestCase._fixture_teardown() in django.test.testcases.
If you want to inspect the test db during test execution, I recommend setting a debugger breakpoint in the test case you want to inspect.
I'm going to mark this wontfix, because it wont work anywhere near to how you probably expect it to work:
So, --keepdb would only be useful for the very last test, if and only if that test is a doctest, raw unit test, or TransactionTestCase. Given how difficult it is to explain the limited cases where this option actually will do something useful, I'm not especially inclined to include it in trunk.