Skip to content

Instantly share code, notes, and snippets.

@devops-school
Created December 1, 2023 05:37
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/f0471da2b38fe844a7bf13bdbc0c34ac to your computer and use it in GitHub Desktop.
Save devops-school/f0471da2b38fe844a7bf13bdbc0c34ac to your computer and use it in GitHub Desktop.
Python Test Runners - pytest -n
# pip install pytest
# tests/test_parallel.py
import pytest
import time
@pytest.mark.parametrize("task_id", range(1, 6))
def test_concurrent_task(task_id):
"""Simulate concurrent tasks that take some time to complete."""
time.sleep(1) # Simulate a task that takes 1 second
assert True, f"Task {task_id} completed successfully."
def test_non_concurrent_task():
"""A non-concurrent task."""
assert True, "Non-concurrent task completed."
# pytest -n 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment