Skip to content

Commit e9cfc13

Browse files
committed
Refactor runtests to allow TestEnv
1 parent 4d1ed14 commit e9cfc13

File tree

2 files changed

+82
-62
lines changed

2 files changed

+82
-62
lines changed

test/preliminaries.jl

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using MLJBase
2+
if !MLJBase.TESTING
3+
error(
4+
"To test MLJBase, the environment variable "*
5+
"`TEST_MLJBASE` must be set to `\"true\"`\n"*
6+
"You can do this in the REPL with `ENV[\"TEST_MLJBASE\"]=\"true\"`"
7+
)
8+
end
9+
10+
using Distributed
11+
# Thanks to https://stackoverflow.com/a/70895939/5056635 for the exeflags tip.
12+
addprocs(; exeflags="--project=$(Base.active_project())")
13+
14+
@info "nprocs() = $(nprocs())"
15+
@static if VERSION >= v"1.3.0-DEV.573"
16+
import .Threads
17+
@info "nthreads() = $(Threads.nthreads())"
18+
else
19+
@info "Running julia $(VERSION). Multithreading tests excluded. "
20+
end
21+
22+
@everywhere begin
23+
using MLJModelInterface
24+
using MLJBase
25+
using Test
26+
using CategoricalArrays
27+
using Logging
28+
using ComputationalResources
29+
using StableRNGs
30+
end
31+
32+
import TypedTables
33+
using Tables
34+
35+
function include_everywhere(filepath)
36+
include(filepath) # Load on Node 1 first, triggering any precompile
37+
if nprocs() > 1
38+
fullpath = joinpath(@__DIR__, filepath)
39+
@sync for p in workers()
40+
@async remotecall_wait(include, p, fullpath)
41+
end
42+
end
43+
end
44+
45+
include("test_utilities.jl")
46+
47+
# load Models module containing model implementations for testing:
48+
print("Loading some models for testing...")
49+
include_everywhere("_models/models.jl")
50+
print("\r \r")
51+
52+
# enable conditional testing of modules by providing test_args
53+
# e.g. `Pkg.test("MLJBase", test_args=["misc"])`
54+
RUN_ALL_TESTS = isempty(ARGS)
55+
macro conditional_testset(name, expr)
56+
name = string(name)
57+
esc(quote
58+
if RUN_ALL_TESTS || $name in ARGS
59+
@testset $name $expr
60+
end
61+
end)
62+
end
63+
64+
# To avoid printing `@conditional_testset (macro with 1 method)`
65+
# when loading this file via `include("test/preliminaries.jl")`.
66+
nothing

test/runtests.jl

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,19 @@
1-
using Distributed
2-
addprocs()
3-
4-
5-
using MLJBase
6-
if !MLJBase.TESTING
7-
error(
8-
"To test MLJBase, the environment variable "*
9-
"`TEST_MLJBASE` must be set to `\"true\"`\n"*
10-
"You can do this in the REPL with `ENV[\"TEST_MLJBASE\"]=\"true\"`"
11-
)
12-
end
13-
14-
@info "nprocs() = $(nprocs())"
15-
@static if VERSION >= v"1.3.0-DEV.573"
16-
import .Threads
17-
@info "nthreads() = $(Threads.nthreads())"
18-
else
19-
@info "Running julia $(VERSION). Multithreading tests excluded. "
20-
end
21-
22-
@everywhere begin
23-
using MLJModelInterface
24-
using MLJBase
25-
using Test
26-
using CategoricalArrays
27-
using Logging
28-
using ComputationalResources
29-
using StableRNGs
30-
end
31-
32-
import TypedTables
33-
using Tables
34-
35-
function include_everywhere(filepath)
36-
include(filepath) # Load on Node 1 first, triggering any precompile
37-
if nprocs() > 1
38-
fullpath = joinpath(@__DIR__, filepath)
39-
@sync for p in workers()
40-
@async remotecall_wait(include, p, fullpath)
41-
end
42-
end
43-
end
44-
45-
include("test_utilities.jl")
46-
47-
# load Models module containing model implementations for testing:
48-
print("Loading some models for testing...")
49-
include_everywhere("_models/models.jl")
50-
print("\r \r")
51-
52-
# enable conditional testing of modules by providing test_args
53-
# e.g. `Pkg.test("MLJBase", test_args=["misc"])`
54-
RUN_ALL_TESTS = isempty(ARGS)
55-
macro conditional_testset(name, expr)
56-
name = string(name)
57-
esc(quote
58-
if RUN_ALL_TESTS || $name in ARGS
59-
@testset $name $expr
60-
end
61-
end)
62-
end
1+
# To speed up the development workflow, use `TestEnv`.
2+
# For example:
3+
# ```
4+
# $ julia --project
5+
#
6+
# julia> ENV["TEST_MLJBASE"] = "true"
7+
#
8+
# julia> using TestEnv; TestEnv.activate()
9+
#
10+
# julia> include("test/preliminaries.jl")
11+
# [...]
12+
#
13+
# julia> include("test/resampling.jl")
14+
# [...]
15+
# ```
16+
include("preliminaries.jl")
6317

6418
@conditional_testset "misc" begin
6519
@test include("utilities.jl")

0 commit comments

Comments
 (0)