I'm learning threads in Python and thought unit testing would fit my needs.
Using this http://www.tutorialspoint.com/python/python_multithreading.htm as my point of origin. However when i'm using time.sleep() in my function, the test seems to return from that code block.
import unittest
import thread
import time
class Test(unittest.TestCase):
def test_threads(self):
thread.start_new_thread(self.print_time, ("Thread 1", 1))
def print_time(self, threadName, delay):
count = 0
while count < 5:
time.sleep(delay)
count += 1
print "%s: %s" % (threadName, time.ctime(time.time()))
if __name__ == "__main__":
unittest.main()
Using this code outputs nothing. Getting rid of time.sleep(delay) outputs:
Thread 1: Mon Aug 03 11:36:56 2015
Thread 1: Mon Aug 03 11:36:56 2015
Thread 1: Mon Aug 03 11:36:56 2015
Thread 1: Mon Aug 03 11:36:56 2015
Thread 1: Mon Aug 03 11:36:56 2015
How can I use time.sleep() when i'm using unit test in Python?