I am using python unittest and would like to write a test that runs multiple threads and waits for them to complete. unittest execute a function that has several unittest statements. If any of the statements fails, I want the test to fail. This does not seem to be the case.
EDIT: Minimal runnable example (python3)
import unittest import threading class MyTests(unittest.TestCase): def test_sample(self): t = threading.Thread(target=lambda: self.fail()) t.start() t.join() if __name__ == '__main__': unittest.main()
and output:
sh-4.3$ python main.py -v test_sample (__main__.MyTests) ... Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib64/python2.7/threading.py", line 813, in __bootstrap_inner self.run() File "/usr/lib64/python2.7/threading.py", line 766, in run self.__target(*self.__args, **self.__kwargs) File "main.py", line 7, in <lambda> t = threading.Thread(target=lambda: self.fail()) File "/usr/lib64/python2.7/unittest/case.py", line 450, in fail raise self.failureException(msg) AssertionError: None ok ---------------------------------------------------------------------- Ran 1 test in 0.002s OK
source share