0
0
PyTesttesting~20 mins

Parallel execution in CI in PyTest - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parallel Execution Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Understanding pytest-xdist parallel test execution output
Given the pytest command below executed with pytest-xdist for parallel testing:
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
ATests run sequentially but pytest-xdist reports parallel execution without speedup.
BAll three tests run sequentially on the same worker, taking about 3 seconds total.
CTests run in parallel but only two workers are used, taking about 2 seconds total.
DTests run in parallel across 3 workers, completing in about 1 second total.
Attempts:
2 left
💡 Hint
pytest-xdist distributes tests across workers to run them simultaneously.
assertion
intermediate
1: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']
Aassert logs == ['PASSED', 'PASSED', 'PASSED']
Bassert all('PASSED' in log for log in logs)
Cassert logs.count('PASSED') == 3
Dassert any('PASSED' in log for log in logs)
Attempts:
2 left
💡 Hint
Check each log individually for the substring.
🔧 Debug
advanced
2: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?
ATests share global state or resources causing race conditions.
Bpytest-xdist does not support parallel execution on CI servers.
CThe test code has syntax errors that only appear in CI.
DThe CI server has insufficient CPU cores to run tests.
Attempts:
2 left
💡 Hint
Parallel tests must avoid shared mutable state.
framework
advanced
2:00remaining
Configuring pytest for parallel execution in CI
Which pytest configuration snippet correctly enables parallel test execution with 4 workers in a CI environment?
A
[pytest]
addopts = -n 4 --dist=loadfile
B
[pytest]
addopts = --workers=4 --dist=loadfile
C
[pytest]
addopts = -n 4 --dist=loadscope
D
[pytest]
addopts = --parallel=4 --dist=loadscope
Attempts:
2 left
💡 Hint
The '-n' option sets the number of workers.
🧠 Conceptual
expert
2: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?
ABecause isolated tests require more CPU resources in parallel.
BBecause parallel tests always run slower, isolation improves speed.
CBecause parallel tests may run simultaneously, shared state can cause unpredictable failures.
DBecause CI pipelines do not support parallel execution without isolation.
Attempts:
2 left
💡 Hint
Think about what happens if tests share data at the same time.