I have a function, which I want to test, but spawns a thread, which can live long enough to wait its end. How to not wait the thread's end in this situation? I use django's unittests, but it is not the point, I guess. Example below:
import threading
from time import sleep
from unittest import TestCase
def long_fun():
threading.Thread(target=sleep, args=(60 * 60,)).start()
class TestLongFun(TestCase):
def test_long_fun(self):
long_fun()
self.assertTrue(1)
So, after launching the tests I have to wait until long_fun
's thread ends it's execution, but I want the thread to end after the assertion happens. Is there a way to mock it or something?