You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -14,40 +21,51 @@ This page covers advanced features of `ParallelTestRunner` for customizing test
14
21
By default, [`runtests`](@ref) automatically discovers all `.jl` files in your `test/` directory (excluding `runtests.jl` itself) using the `find_tests` function.
15
22
You can customize which tests to run by providing a custom `testsuite` dictionary:
16
23
17
-
```julia
24
+
```@example mypackage
25
+
using ParallelTestRunner
26
+
using MyPackage
27
+
18
28
# Manually define your test suite
19
29
testsuite = Dict(
20
30
"basic" => quote
21
31
include("basic.jl")
22
32
end,
23
33
"advanced" => quote
24
34
include("advanced.jl")
35
+
@test 40 + 2 ≈ 42
25
36
end
26
37
)
27
38
28
-
runtests(MyModule, ARGS; testsuite)
39
+
cd(test_dir) do # hide
40
+
runtests(MyPackage, ARGS; testsuite)
41
+
end # hide
29
42
```
30
43
31
44
## Filtering Test Files
32
45
33
46
You can also use [`find_tests`](@ref) to automatically discover test files and then filter or modify them.
34
47
This requires manually parsing arguments so that filtering is only applied when the user did not request specific tests to run:
35
48
36
-
```julia
49
+
```@example mypackage
50
+
using ParallelTestRunner
51
+
using MyPackage
52
+
37
53
# Start with autodiscovered tests
54
+
cd(test_dir) do # hide
38
55
testsuite = find_tests(pwd())
39
56
40
57
# Parse arguments
41
58
args = parse_args(ARGS)
42
59
43
60
if filter_tests!(testsuite, args)
44
-
# Remove tests that shouldn't run on Windows
45
-
if Sys.iswindows()
46
-
delete!(testsuite, "ext/specialfunctions")
61
+
# Remove tests that shouldn't run on non-Windows systems
62
+
if !Sys.iswindows()
63
+
delete!(testsuite, "advanced")
47
64
end
48
65
end
49
66
50
-
runtests(MyModule, args; testsuite)
67
+
runtests(MyPackage, args; testsuite)
68
+
end # hide
51
69
```
52
70
53
71
The [`filter_tests!`](@ref) function returns `true` if no positional arguments were provided (allowing additional filtering) and `false` if the user specified specific tests (preventing further filtering).
@@ -60,20 +78,20 @@ This is useful for:
60
78
- Defining constants, defaults or helper functions
61
79
- Setting up test infrastructure
62
80
63
-
```julia
81
+
```@example mypackage
64
82
using ParallelTestRunner
83
+
using MyPackage
65
84
66
85
const init_code = quote
67
-
using Test
68
-
using MyPackage
69
-
70
86
# Define a helper function available to all tests
71
87
function test_helper(x)
72
88
return x * 2
73
89
end
74
90
end
75
91
92
+
cd(test_dir) do # hide
76
93
runtests(MyPackage, ARGS; init_code)
94
+
end # hide
77
95
```
78
96
79
97
The `init_code` is evaluated in each test's sandbox module, so all definitions are available to your test files.
@@ -82,8 +100,9 @@ The `init_code` is evaluated in each test's sandbox module, so all definitions a
82
100
83
101
For tests that require specific environment variables or Julia flags, you can use the `test_worker` keyword argument to [`runtests`](@ref) to assign tests to custom workers:
84
102
85
-
```julia
103
+
```@example mypackage
86
104
using ParallelTestRunner
105
+
using MyPackage
87
106
88
107
function test_worker(name)
89
108
if name == "needs_env_var"
@@ -120,8 +139,9 @@ The `test_worker` function receives the test name and should return either:
120
139
121
140
If your package needs to accept its own command-line arguments in addition to `ParallelTestRunner`'s options, use [`parse_args`](@ref) with custom flags:
@@ -132,10 +152,12 @@ if args.custom["myflag"] !== nothing
132
152
end
133
153
134
154
# Pass parsed args to runtests
155
+
cd(test_dir) do # hide
135
156
runtests(MyPackage, args)
157
+
end # hide
136
158
```
137
159
138
-
Custom flags are stored in the `custom` field of the `ParsedArgs` object, with values of `nothing` (not set) or `Some(value)` (set, with optional value).
160
+
Custom flags are stored in the `custom` field of the [`ParsedArgs`](@ref) object, with values of `nothing` (not set) or `Some(value)` (set, with optional value).
139
161
140
162
## Interactive use
141
163
@@ -146,11 +168,11 @@ For example, here is how we could run the subset of test files that start with t
146
168
# Start julia in an environment where `MyPackage.jl` is available
147
169
julia --project
148
170
```
149
-
```julia-repl
150
-
julia> using Pkg
171
+
```@repl mypackage
172
+
using Pkg
151
173
152
174
# No need to start a fresh session to change threading
[ParallelTestRunner.jl](https://github.com/JuliaTesting/ParallelTestRunner.jl) is a simple parallel test runner for Julia tests with automatic test discovery.
11
18
It runs each test file concurrently in isolated worker processes, providing real-time progress output and efficient resource management.
12
19
@@ -19,11 +26,13 @@ It runs each test file concurrently in isolated worker processes, providing real
19
26
20
27
2.**Update your `test/runtests.jl`**:
21
28
22
-
```julia
29
+
```@example mypackage
23
30
using MyPackage
24
31
using ParallelTestRunner
25
32
33
+
cd(test_dir) do # hide
26
34
runtests(MyPackage, ARGS)
35
+
end # hide
27
36
```
28
37
29
38
That's it! `ParallelTestRunner` will automatically:
@@ -108,14 +117,6 @@ The test runner provides real-time output showing:
108
117
- Memory allocation
109
118
- RSS (Resident Set Size) memory usage
110
119
111
-
Example output:
112
-
113
-
```
114
-
Test | Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB) |
0 commit comments