'Is it possible to get an interactive django shell using the test database?
When running tests, you can do:
./manage.py test --keepdb
To run your tests, and keep the test database. Is it possible to have the django shell actually connect to it, so we can interactively access the test database the same way the Django shell can normally work with the production database?
Note that the answer and its comments here imply that you can access it by doing something like:
from django import test
test.utils.setup_test_environment()
from django.db import connection
db = connection.creation.create_test_db(keepdb=True)
But when I do that, my database appears to be empty when I do queries.
Solution 1:[1]
I ran into this, at first I thought it was because the codebase I'm working on has a flush call in the teardown function, but my DB was still empty after removing those. Maybe there were more flushes somewhere I didn't catch.
I ended up getting around this by sleeping at the end of the test, so it doesn't exit and doesn't clean up.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | rtaft |
