@@ -1985,14 +1985,18 @@ end
19851985
19861986
19871987function get_threads_spec ()
1988- if Threads. nthreads (:interactive ) > 0
1988+ if haskey (ENV , " JULIA_NUM_THREADS" )
1989+ # if set, prefer JULIA_NUM_THREADS because this is passed to the test worker via --threads
1990+ # which takes precedence in the worker
1991+ ENV [" JULIA_NUM_THREADS" ]
1992+ elseif Threads. nthreads (:interactive ) > 0
19891993 " $(Threads. nthreads (:default )) ,$(Threads. nthreads (:interactive )) "
19901994 else
19911995 " $(Threads. nthreads (:default )) "
19921996 end
19931997end
19941998
1995- function gen_subprocess_flags (source_path:: String ; coverage, julia_args)
1999+ function gen_subprocess_flags (source_path:: String ; coverage, julia_args:: Cmd )
19962000 coverage_arg = if coverage isa Bool
19972001 # source_path is the package root, not "src" so "ext" etc. is included
19982002 coverage ? string (" @" , source_path) : " none"
@@ -2330,7 +2334,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
23302334 test_fn != = nothing && test_fn ()
23312335 sandbox_ctx = Context (;io= ctx. io)
23322336 status (sandbox_ctx. env, sandbox_ctx. registries; mode= PKGMODE_COMBINED, io= sandbox_ctx. io, ignore_indent = false , show_usagetips = false )
2333- flags = gen_subprocess_flags (source_path; coverage,julia_args)
2337+ flags = gen_subprocess_flags (source_path; coverage, julia_args)
23342338
23352339 if should_autoprecompile ()
23362340 cacheflags = Base. CacheFlags (parse (UInt8, read (` $(Base. julia_cmd ()) $(flags) --eval 'show(ccall(:jl_cache_flags, UInt8, ()))'` , String)))
@@ -2340,7 +2344,7 @@ function test(ctx::Context, pkgs::Vector{PackageSpec};
23402344 printpkgstyle (ctx. io, :Testing , " Running tests..." )
23412345 flush (ctx. io)
23422346 code = gen_test_code (source_path; test_args)
2343- cmd = ` $(Base. julia_cmd ()) $(flags) --threads=$(get_threads_spec ()) --eval $code `
2347+ cmd = ` $(Base. julia_cmd ()) --threads=$(get_threads_spec ()) $(flags ) --eval $code `
23442348 p, interrupted = subprocess_handler (cmd, ctx. io, " Tests interrupted. Exiting the test process" )
23452349 if success (p)
23462350 printpkgstyle (ctx. io, :Testing , pkg. name * " tests passed " )
0 commit comments