Test Overview
This test demonstrates running two simple tests at the same time (in parallel). It verifies that both tests complete successfully without waiting for each other.
This test demonstrates running two simple tests at the same time (in parallel). It verifies that both tests complete successfully without waiting for each other.
import unittest import time from concurrent.futures import ThreadPoolExecutor class SimpleTest(unittest.TestCase): def test_one(self): time.sleep(2) # Simulate a delay self.assertEqual(1 + 1, 2) def test_two(self): time.sleep(2) # Simulate a delay self.assertTrue('hello'.islower()) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(SimpleTest) with ThreadPoolExecutor(max_workers=2) as executor: futures = [executor.submit(unittest.TextTestRunner().run, test) for test in suite] results = [f.result() for f in futures] # Check all tests passed assert all(result.wasSuccessful() for result in results), "Some tests failed"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test suite loads two test methods: test_one and test_two | Two test cases ready to run | - | PASS |
| 2 | ThreadPoolExecutor starts and runs test_one and test_two in parallel threads | Both tests running simultaneously, each sleeping for 2 seconds | - | PASS |
| 3 | test_one completes and asserts 1 + 1 equals 2 | test_one finished successfully | assertEqual(1 + 1, 2) | PASS |
| 4 | test_two completes and asserts 'hello' is lowercase | test_two finished successfully | assertTrue('hello'.islower()) | PASS |
| 5 | Main thread collects results from both tests | Both tests passed | assert all tests passed | PASS |