Challenge - 5 Problems
Parallel Execution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Understanding pytest-xdist parallel test execution output
Given the pytest command below executed with pytest-xdist for parallel testing:
What is the expected output behavior regarding test distribution?
pytest -n 3 test_sample.py
What is the expected output behavior regarding test distribution?
PyTest
import time import pytest def test_one(): time.sleep(1) assert True def test_two(): time.sleep(1) assert True def test_three(): time.sleep(1) assert True
Attempts:
2 left
💡 Hint
pytest-xdist distributes tests across workers to run them simultaneously.
✗ Incorrect
Using '-n 3' with pytest-xdist runs tests on 3 parallel workers. Each test sleeps 1 second, so total time is about 1 second, not 3.
❓ assertion
intermediate1:30remaining
Choosing the correct assertion for parallel test logs
In a CI pipeline running tests in parallel, which assertion best verifies that all test logs contain the string 'PASSED' exactly once per test?
PyTest
logs = ['test_one PASSED', 'test_two PASSED', 'test_three PASSED']
Attempts:
2 left
💡 Hint
Check each log individually for the substring.
✗ Incorrect
Option B checks that every log string contains 'PASSED'. Option B is invalid because logs is a list of strings, not a list of 'PASSED'. Option B expects exact strings, which is incorrect. Option B only checks if any log contains 'PASSED', not all.
🔧 Debug
advanced2:00remaining
Debugging flaky tests in parallel CI runs
A test suite runs fine locally but intermittently fails in CI when run with pytest-xdist parallel execution. Which is the most likely cause?
Attempts:
2 left
💡 Hint
Parallel tests must avoid shared mutable state.
✗ Incorrect
Flaky failures in parallel runs often come from tests sharing global variables or files, causing race conditions. pytest-xdist supports parallel runs on CI. Syntax errors cause consistent failures. CPU cores affect speed but not correctness.
❓ framework
advanced2:00remaining
Configuring pytest for parallel execution in CI
Which pytest configuration snippet correctly enables parallel test execution with 4 workers in a CI environment?
Attempts:
2 left
💡 Hint
The '-n' option sets the number of workers.
✗ Incorrect
Option A uses '-n 4' to specify 4 workers and '--dist=loadfile' to distribute tests by file, which is valid. Option A uses invalid '--dist=loadscope'. Option A uses invalid '--workers'. Option A uses invalid '--parallel'.
🧠 Conceptual
expert2:30remaining
Impact of parallel test execution on test isolation in CI
Why is test isolation especially critical when running tests in parallel in a CI pipeline?
Attempts:
2 left
💡 Hint
Think about what happens if tests share data at the same time.
✗ Incorrect
Parallel tests run at the same time, so if they share state or resources, they can interfere and cause random failures. Isolation prevents this by keeping tests independent.