Skip to main content

ParallelTestSuite

Run a series of tests in parallel in several processes.

Attributes

AttributeTypeDescription
init_workercallable = _init_workerThe function used to initialize each worker process in the multiprocessing pool.
process_setupcallable = _process_setup_stubA hook function executed within each worker process to perform environment-specific setup.
process_setup_argstuple = ()A tuple of arguments passed to the process_setup function during worker initialization.
run_subsuitecallable = _run_subsuiteThe function responsible for executing an individual test subsuite within a worker process.
runner_classclass = RemoteTestRunnerThe test runner class instantiated within worker processes to execute subsuites and collect results.

Constructor

Signature

def ParallelTestSuite(
subsuites: list,
processes: int,
failfast: bool = False,
debug_mode: bool = False,
buffer: bool = False
) - > null

Parameters

NameTypeDescription
subsuiteslistA collection of test suites to be executed in parallel.
processesintThe number of worker processes to use for parallel execution.
failfastbool = FalseWhether to stop the test run on the first error or failure.
debug_modebool = FalseFlag to enable debug mode during test execution.
bufferbool = FalseWhether to buffer stdout and stderr during test execution.

Methods


run()

@classmethod
def run(
result: unittest.TestResult
) - > unittest.TestResult

Distribute TestCases across workers. Return an identifier of each TestCase with its result in order to use imap_unordered to show results as soon as they're available.

Parameters

NameTypeDescription
resultunittest.TestResultThe test result object to which the outcomes of the executed tests will be reported.

Returns

TypeDescription
unittest.TestResultThe updated test result object containing the aggregated outcomes from all parallel workers.

handle_event()

@classmethod
def handle_event(
result: unittest.TestResult,
tests: list,
event: tuple
)

Dispatches test execution events received from worker processes to the main result collector. It maps worker event data back to specific test instances or error holders.

Parameters

NameTypeDescription
resultunittest.TestResultThe result collector that will process the specific event (e.g., addSuccess, addError).
testslistThe list of test cases belonging to the subsuite that generated the event.
eventtupleA tuple containing the event name, the test index, and any associated arguments or tracebacks.

initialize_suite()

@classmethod
def initialize_suite()

Prepares the suite for parallel execution by capturing database settings and serialized contents. This ensures that worker processes spawned via 'spawn' or 'forkserver' have access to the necessary environment state.