Skip to content

Instantly share code, notes, and snippets.

@devops-school
Created December 1, 2023 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devops-school/dc94ac7919972cabe5e10f612ec5a6a2 to your computer and use it in GitHub Desktop.
Save devops-school/dc94ac7919972cabe5e10f612ec5a6a2 to your computer and use it in GitHub Desktop.
Python Test Runners - Pytest-xdist
# pip install pytest pytest-xdist
# tests/test_parallel_execution.py
# In this code, we have three test functions representing tasks that can run concurrently.
import pytest
import time
def test_task_1():
"""Simulate task 1 that takes some time to complete."""
time.sleep(1) # Simulate a task that takes 1 second
assert True, "Task 1 completed successfully."
def test_task_2():
"""Simulate task 2 that takes some time to complete."""
time.sleep(1) # Simulate a task that takes 1 second
assert True, "Task 2 completed successfully."
def test_task_3():
"""Simulate task 3 that takes some time to complete."""
time.sleep(1) # Simulate a task that takes 1 second
assert True, "Task 3 completed successfully."
# pytest -n 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment