Introduction
Running many tests one after another can take a long time, especially for big projects. Parallel test execution solves this by running multiple tests at the same time, making the process faster and more efficient.
Imagine a group of friends cleaning a house. If only one person cleans each room one after another, it takes a long time. But if everyone cleans different rooms at the same time, the whole house gets clean much faster.
┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ Test 1 │ │ Test 2 │ │ Test 3 │ │ (Sequential) │ │ (Sequential) │ │ (Sequential) │ └──────┬────────┘ └──────┬────────┘ └──────┬────────┘ │ │ │ │ │ │ ▼ ▼ ▼ ┌───────────────────────────────────────────────────────────┐ │ Total time: Long │ └───────────────────────────────────────────────────────────┘ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ Test 1 │ │ Test 2 │ │ Test 3 │ │ (Parallel) │ │ (Parallel) │ │ (Parallel) │ └──────┬────────┘ └──────┬────────┘ └──────┬────────┘ │ │ │ │ │ │ ▼ ▼ ▼ ┌───────────────────────────────────────────────┐ │ Total time: Much shorter │ └───────────────────────────────────────────────┘
import unittest import time class TestExample(unittest.TestCase): def test_one(self): time.sleep(1) self.assertTrue(True) def test_two(self): time.sleep(1) self.assertTrue(True) if __name__ == '__main__': unittest.main(verbosity=2)