Run two simple tests in parallel and verify both pass
Preconditions (2)
✅ Expected Result: Both tests run at the same time and pass successfully
import pytest def test_addition(): assert 2 + 3 == 5 def test_subtraction(): assert 5 - 3 == 2 # To run these tests in parallel, use the command: # pytest -n 2
This script defines two simple test functions using pytest. Each test checks a basic math operation with an assertion.
We use pytest -n 2 to run both tests at the same time in parallel using the pytest-xdist plugin.
This approach helps speed up test execution by running tests concurrently. The tests are independent, so they do not affect each other.
Now add a third test for multiplication and run all three tests in parallel
parallel test execution in software testing?parallel = true typically enables parallel runs in configs.parallel = true -> Option Dstart test1
start test2
wait for test1
wait for test2
print('All tests done')
What will be the output if both tests pass quickly?Pass the test and this pattern moves unknown