Test Overview
This test runs two simple tests in parallel using pytest-xdist. It verifies that running tests in parallel reduces the total test execution time compared to running them sequentially.
This test runs two simple tests in parallel using pytest-xdist. It verifies that running tests in parallel reduces the total test execution time compared to running them sequentially.
import time import pytest def test_sleep_1(): time.sleep(2) assert True def test_sleep_2(): time.sleep(2) assert True # To run in parallel: pytest -n 2
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and detects two test functions | Test suite loaded with test_sleep_1 and test_sleep_2 | - | PASS |
| 2 | Pytest-xdist plugin runs test_sleep_1 and test_sleep_2 in parallel on 2 workers | Two separate test processes start simultaneously | - | PASS |
| 3 | Each test sleeps for 2 seconds concurrently | Both tests are waiting during sleep | - | PASS |
| 4 | Each test completes and asserts True | Both tests finish successfully | Assert True in both tests | PASS |
| 5 | Test runner reports total time taken is about 2 seconds | Test report shows both tests passed quickly | Total time < 4 seconds (sequential time) | PASS |