Created
December 1, 2023 05:39
-
-
Save devops-school/8f165edc9936f7dbec71f635f5453326 to your computer and use it in GitHub Desktop.
Python Test Runners - unittest-parallel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install unittest-parallel | |
# tests/test_parallel_execution.py | |
# In this code, we have a unittest test case class TestParallelExecution with three test methods representing tasks that can run concurrently. | |
import time | |
import unittest | |
class TestParallelExecution(unittest.TestCase): | |
def test_task_1(self): | |
"""Simulate task 1 that takes some time to complete.""" | |
time.sleep(1) # Simulate a task that takes 1 second | |
self.assertTrue(True, "Task 1 completed successfully.") | |
def test_task_2(self): | |
"""Simulate task 2 that takes some time to complete.""" | |
time.sleep(1) # Simulate a task that takes 1 second | |
self.assertTrue(True, "Task 2 completed successfully.") | |
def test_task_3(self): | |
"""Simulate task 3 that takes some time to complete.""" | |
time.sleep(1) # Simulate a task that takes 1 second | |
self.assertTrue(True, "Task 3 completed successfully.") | |
# To run the tests in parallel using unittest-parallel, you can specify the number of worker processes to use with the -w option. For example, to run tests with 2 worker processes in parallel, you can run: | |
# unittest-parallel discover -s tests -p 'test_parallel_execution.py' -w 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment