Recall & Review
beginner
What is pytest-xdist used for?
pytest-xdist is a plugin for pytest that allows tests to run in parallel across multiple CPUs or hosts, speeding up test execution.
Click to reveal answer
beginner
How do you run tests in parallel using pytest-xdist?
Use the command pytest -n NUM where NUM is the number of parallel workers you want to run tests on.
Click to reveal answer
intermediate
What does the -n auto option do in pytest-xdist?
It automatically detects the number of CPU cores on your machine and runs that many parallel test workers.
Click to reveal answer
intermediate
Name one common issue when running tests in parallel with pytest-xdist.
Tests that share or modify global state or resources can cause conflicts or flaky results when run in parallel.
Click to reveal answer
advanced
How can you ensure tests are safe to run in parallel with pytest-xdist?
Design tests to be independent, avoid shared state, use fixtures with proper scope, and isolate external resources like files or databases.
Click to reveal answer
Which command runs tests in parallel using 4 workers with pytest-xdist?
✗ Incorrect
The correct syntax to run tests in parallel with 4 workers is pytest -n 4.
What does pytest-xdist help improve?
✗ Incorrect
pytest-xdist improves test execution speed by running tests in parallel.
If tests share global variables, what problem might occur when using pytest-xdist?
✗ Incorrect
Sharing global variables can cause conflicts and unpredictable test results when tests run in parallel.
How does pytest-xdist decide the number of workers with -n auto?
✗ Incorrect
-n auto runs tests using the number of CPU cores detected on the machine.
Which of these is NOT a best practice when using pytest-xdist?
✗ Incorrect
Running tests that modify the same file simultaneously can cause conflicts and should be avoided.
Explain how pytest-xdist speeds up test execution and what you must consider when using it.
Think about how dividing work helps and what problems parallelism can cause.
You got /5 concepts.
Describe common issues that can happen when running tests in parallel with pytest-xdist and how to prevent them.
Consider what happens if tests interfere with each other.
You got /5 concepts.