Complete the code to run tests in parallel using threads.
from concurrent.futures import ThreadPoolExecutor def run_tests(): with ThreadPoolExecutor(max_workers=[1]) as executor: executor.map(run_single_test, test_cases)
Setting max_workers=10 allows running up to 10 tests in parallel threads.
Complete the code to wait for all parallel tests to finish before proceeding.
futures = [executor.submit(run_single_test, test) for test in test_cases] for future in [1]: future.result()
Iterating over futures and calling result() waits for each test to complete.
Fix the error in the code to correctly run tests in parallel using multiprocessing.
from multiprocessing import Pool def run_parallel_tests(): with Pool([1]) as pool: results = pool.map(run_single_test, test_cases)
Using a positive integer like 4 sets the number of worker processes correctly.
Fill both blanks to create a dictionary comprehension that maps test names to their results after parallel execution.
results = {test[1]: result for test, result in zip(test_cases, [2])}Accessing test.name gets the test name, and pool.map(...) runs tests in parallel returning results.
Fill all three blanks to filter and run only failed tests in parallel, collecting their names and results.
failed_tests = [test for test in test_cases if test.status == [1]] results = {test.[2]: res for test, res in zip(failed_tests, pool.[3](run_single_test, failed_tests))}
We filter tests with status 'failed', access their name, and use pool.map to run them in parallel.