0
0
PyTesttesting~20 mins

pytest-xdist for parallel execution - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
pytest-xdist Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
A2 passed in ~1 second
B1 passed, 1 failed in ~1 second
C2 passed in ~2 seconds
DTests skipped due to worker error
Attempts:
2 left
💡 Hint
Think about how parallel execution affects total test time.
assertion
intermediate
2: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?
Aassert result.testscollected == 3 and result.testsfailed == 0
Bassert result.testscollected == 6 and result.testsfailed > 0
Cassert result.testscollected == 6 and result.testsfailed == 0
Dassert result.testscollected == 0 and result.testsfailed == 0
Attempts:
2 left
💡 Hint
Total tests collected is independent of number of workers.
🔧 Debug
advanced
2: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?
Apytest-xdist disables assertions
Bpytest-xdist does not support parallel execution
CTests are too fast to run in parallel
DTests share and modify global state causing race conditions
Attempts:
2 left
💡 Hint
Think about what changes when tests run in parallel.
framework
advanced
2: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?
ADisable transactions in tests
BUse separate database instances or schemas per worker
CUse a single shared database connection for all tests
DRun all tests sequentially to avoid conflicts
Attempts:
2 left
💡 Hint
Think about how parallel tests can interfere with shared resources.
🧠 Conceptual
expert
2: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?
ALoad scheduling mode
BStatic scheduling mode
CRound-robin scheduling mode
DBatch scheduling mode
Attempts:
2 left
💡 Hint
One mode assigns tests dynamically to balance workload.