python - How to test other thread that access database -
it seem database used django during tests isn't shared other thread
for example:
inside testcase class :
def my_test(self): print(mymodel.objects.all()) my_function()
inside class :
def worker(): print(mymodel.objects.all()) def my_function(): thread = thread(target=worker) thread.start()
console result :
[<mymodel object>, <mymodel object>, <mymodel object> ... ] []
so first call, inside thread, doesn't use test db anymore.
i looked @ : django: using same test database in separate thread , tried use same db "name" , "test_name" doesn't work me
what test threads if accessing db ?
django's testcase
runs each test class in single transaction. changes not committed, other threads cannot read effects of changes.
the solution use transactiontestcase
. run queries in default autocommit mode, , changes available other threads.
Comments
Post a Comment