PZ
Size: a a a
PZ
PZ
test
🔐
🔐
PZ
If your code attempts to access the database when its modules are compiled, this will occur before the test database is set up, with potentially unexpected results. For example, if you have a database query in module-level code and a real database exists, production data could pollute your tests.
from django.conf import settings
print('xxxxx module level', settings.DATABASES['default']['NAME'])
class FooTest(TestCase):
def test_1(self):
print('xxxxx inside test', settings.DATABASES['default']['NAME'])
$ ./manage.py test 2>&1 | grep xxx
xxxxx before django
xxxxx after test_django
ПГ
DT
ПГ
SR
АМ
A
A
АМ
SR
НВ
A
A
АМ