Challenge - 5 Problems
pytest-xdist Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest-xdist parallel test run
Given the following pytest test file and running it with pytest-xdist using 2 workers, what will be the output summary line?
PyTest
import time import pytest def test_one(): time.sleep(1) assert True def test_two(): time.sleep(1) assert True
Attempts:
2 left
💡 Hint
Think about how parallel execution affects total test time.
✗ Incorrect
Using pytest-xdist with 2 workers runs tests in parallel, so total time is about the longest single test, not the sum.
❓ assertion
intermediate2:00remaining
Correct assertion for parallel test results
You run pytest with xdist -n 3 on 6 tests. Which assertion correctly checks that all tests passed?
Attempts:
2 left
💡 Hint
Total tests collected is independent of number of workers.
✗ Incorrect
All 6 tests should be collected and none failed if all passed.
🔧 Debug
advanced2:00remaining
Identify cause of flaky test with pytest-xdist
You notice tests sometimes fail when run with pytest-xdist -n 4 but pass when run normally. What is the most likely cause?
Attempts:
2 left
💡 Hint
Think about what changes when tests run in parallel.
✗ Incorrect
Parallel tests can interfere if they share mutable global data without isolation.
❓ framework
advanced2:00remaining
Best practice for using pytest-xdist with database tests
When running database tests in parallel with pytest-xdist, what is the best practice to avoid conflicts?
Attempts:
2 left
💡 Hint
Think about how parallel tests can interfere with shared resources.
✗ Incorrect
Isolating database state per worker prevents data conflicts and test interference.
🧠 Conceptual
expert2:00remaining
Understanding pytest-xdist load scheduling modes
pytest-xdist supports different load scheduling modes. Which mode dynamically assigns tests to workers as they finish, improving load balance?
Attempts:
2 left
💡 Hint
One mode assigns tests dynamically to balance workload.
✗ Incorrect
Load scheduling mode assigns tests to free workers dynamically, reducing idle time.