Hi. I've been using the unit test framework to automate integration tests of the following:-
- multi-threaded python code
- external hardware
- embedded C
I need the tests to fail if even one exception is raised by ay of the threads. Is this possible?
A simple but non-workable solution would be to either
- refactor the code to avoid multi-threading
- test each thread separately
I can't perform either of these because the code interacts asynchronously with the hardware. I've also given a thought to passing messages to forward the exception the main unittest thread but that would require significant testing related changes to the code, and I want to avoid that at this moment.
For example, can I modify the test script below to fail on the exception raised in my_thread without modifying the x.ExceptionRaiser class?
import unittest
import x
class Test(unittest.TestCase):
def test_x(self):
my_thread = x.ExceptionRaiser()
# Test case should fail when thread is started and raises
# an exception.
my_thread.start()
my_thread.join()
if __name__ == '__main__':
unittest.main()