API Reference
Main Functions
ParallelTestRunner.runtests — Function
runtests(mod::Module, args::ParsedArgs;
testsuite::Dict{String,Expr}=find_tests(pwd()),
init_code = :(),
test_worker = Returns(nothing),
stdout = Base.stdout,
stderr = Base.stderr)
runtests(mod::Module, ARGS; ...)Run Julia tests in parallel across multiple worker processes.
Arguments
mod: The module calling runtestsARGS: Command line arguments array, typically fromBase.ARGS. When you run the tests withPkg.test, this can be changed with thetest_argskeyword argument. If the caller needs to accept args too, consider usingparse_argsto parse the arguments first.
Several keyword arguments are also supported:
testsuite: Dictionary mapping test names to expressions to execute (default:find_tests(pwd())). By default, automatically discovers all.jlfiles in the test directory.init_code: Code use to initialize each test's sandbox module (e.g., import auxiliary packages, define constants, etc).test_worker: Optional function that takes a test name and returns a specific worker. When returningnothing, the test will be assigned to any available default worker.stdoutandstderr: I/O streams to write to (default:Base.stdoutandBase.stderr)
Command Line Options
--help: Show usage information and exit--list: List all available test files and exit--verbose: Print more detailed information during test execution--quickfail: Stop the entire test run as soon as any test fails--jobs=N: Use N worker processes (default: based on CPU threads and available memory)TESTS...: Filter test files by name, matched usingstartswith
Behavior
- Automatically discovers all
.jlfiles in the test directory (excludingruntests.jl) - Sorts test files by runtime (longest-running are started first) for load balancing
- Launches worker processes with appropriate Julia flags for testing
- Monitors memory usage and recycles workers that exceed memory limits
- Provides real-time progress output with timing and memory statistics
- Handles interruptions gracefully (Ctrl+C)
- Returns
nothing, but throwsTest.FallbackTestSetExceptionif any tests fail
Examples
# Run all tests with default settings (auto-discovers .jl files)
runtests(MyModule, ARGS)
# Run only tests matching "integration"
runtests(MyModule, ["integration"])
# Define a custom test suite
testsuite = Dict(
"custom" => quote
@test 1 + 1 == 2
end
)
runtests(MyModule, ARGS; testsuite)
# Customize the test suite
testsuite = find_tests(pwd())
args = parse_args(ARGS)
if filter_tests!(testsuite, args)
# Remove a specific test
delete!(testsuite, "slow_test")
end
runtests(MyModule, args; testsuite)Memory Management
Workers are automatically recycled when they exceed memory limits to prevent out-of-memory issues during long test runs. The memory limit is set based on system architecture.
Test Discovery
ParallelTestRunner.find_tests — Function
find_tests(dir::String) -> Dict{String, Expr}Discover test files in a directory and return a test suite dictionary.
Walks through dir and finds all .jl files (excluding runtests.jl), returning a dictionary mapping test names to expression that include each test file.
Argument Parsing
ParallelTestRunner.parse_args — Function
parse_args(args; [custom::Array{String}]) -> ParsedArgsParse command-line arguments for runtests. Typically invoked by passing Base.ARGS.
Fields of this structure represent command-line options, containing nothing when the option was not specified, or Some(optional_value=nothing) when it was.
Custom arguments can be specified via the custom keyword argument, which should be an array of strings representing custom flag names (without the -- prefix). Presence of these flags will be recorded in the custom field of the returned ParsedArgs object.
ParallelTestRunner.filter_tests! — Function
filter_tests!(testsuite, args::ParsedArgs) -> BoolFilter tests in testsuite based on command-line arguments in args.
Returns true if additional filtering may be done by the caller, false otherwise.
Worker Management
ParallelTestRunner.addworker — Function
addworker(; env=Vector{Pair{String, String}}(), exename=nothing, exeflags=nothing)Add a single worker process. To add multiple workers, use addworkers.
Arguments
env: Vector of environment variable pairs to set for the worker process.exename: Custom executable to use for the worker process.exeflags: Custom flags to pass to the worker process.
ParallelTestRunner.addworkers — Function
addworkers(; env=Vector{Pair{String, String}}(), exename=nothing, exeflags=nothing)Add X worker processes. To add a single worker, use addworker.
Arguments
env: Vector of environment variable pairs to set for the worker process.exename: Custom executable to use for the worker process.exeflags: Custom flags to pass to the worker process.
Configuration
ParallelTestRunner.default_njobs — Function
default_njobs()Determine default number of parallel jobs.
Internal Types
ParallelTestRunner.WorkerTestSet — Type
WorkerTestSetA test set wrapper used internally by worker processes. Base.DefaultTestSet detects when it is the top-most and throws a TestSetException containing very little information. By inserting this wrapper as the top-most test set, we can capture the full results.