Challenge - 5 Problems
Worker Distribution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest-xdist with loadscope distribution
Given the following pytest test file and running pytest with
pytest -n 2 --dist=loadscope, what will be the order of test execution across workers?PyTest
import pytest @pytest.mark.scope('module1') def test_a(): pass @pytest.mark.scope('module1') def test_b(): pass @pytest.mark.scope('module2') def test_c(): pass @pytest.mark.scope('module2') def test_d(): pass
Attempts:
2 left
💡 Hint
Loadscope groups tests by their scope marker to minimize setup overhead.
✗ Incorrect
The loadscope distribution groups tests by their scope marker (here 'module1' and 'module2'), so tests with the same scope run on the same worker.
❓ assertion
intermediate1:30remaining
Correct assertion for balanced worker load
You want to assert that pytest-xdist distributed 10 tests evenly across 2 workers. Which assertion correctly verifies this?
Attempts:
2 left
💡 Hint
Balanced load means tests are nearly evenly split, allowing a difference of one.
✗ Incorrect
Option C checks total tests are 10 and the difference between max and min tests per worker is at most 1, which is correct for balanced distribution.
🔧 Debug
advanced2:00remaining
Identify the cause of uneven test distribution
A test suite with 12 tests is run with pytest-xdist using
--dist=loadfile and 3 workers. The distribution is uneven: one worker runs 8 tests, others run 2 each. What is the most likely cause?Attempts:
2 left
💡 Hint
Loadfile groups tests by their file location.
✗ Incorrect
With --dist=loadfile, pytest-xdist assigns all tests from the same file to the same worker, so if one file has many tests, that worker gets more load.
❓ framework
advanced1:30remaining
Choosing the right pytest-xdist distribution mode
Which pytest-xdist distribution mode is best when tests have expensive setup per module and you want to minimize setup duplication?
Attempts:
2 left
💡 Hint
Consider grouping tests by their setup scope.
✗ Incorrect
loadscope groups tests by their scope (like module), so setup runs once per worker, minimizing duplication.
🧠 Conceptual
expert2:30remaining
Impact of worker distribution on flaky tests
How can improper worker distribution in pytest-xdist contribute to flaky test results?
Attempts:
2 left
💡 Hint
Think about shared resources and parallel execution.
✗ Incorrect
If tests that share state run on different workers without proper isolation, race conditions can cause flaky failures.