Skip to content

Conversation

@nickrobinson251
Copy link
Member

Fix #228

Before this PR the newly added test would fail (like below)

$ julia --project -q
julia> using ReTestItems
Precompiling ReTestItems
  1 dependency successfully precompiled in 1 seconds. 2 already precompiled.

julia> pkg = "test/packages/TestOnlyDeps";

julia> cmd = ```
           $(Base.julia_cmd()) --project=$(pkg) -e '
               using ReTestItems, TestOnlyDeps; runtests(TestOnlyDeps; nworkers=1)'
           ```;

julia> run(addenv(cmd, "JULIA_PROJECT" => pkg));
  Activating project at `~/repos/ReTestItems.jl/test/packages/TestOnlyDeps`
┌ Warning: The project dependencies or compat requirements have changed since the manifest was last resolved.
│ It is recommended to `Pkg.resolve()` or consider `Pkg.update()` if necessary.
└ @ Pkg.API ~/repos/rai-julia/usr/share/julia/stdlib/v1.10/Pkg/src/API.jl:1807
[ Info: Scanning for test items in project `TestOnlyDeps` at paths: /Users/nickr/repos/ReTestItems.jl/test/packages/TestOnlyDeps
[ Info: Finished scanning for test items in 0.49 seconds.
[ Info: Scheduling 2 tests on pid 56288 with 1 worker processes and 2 threads per worker.
[ Info: Starting test workers
  Worker 56513:  [ Info: Starting test worker 1 on pid = 56513, with 2 threads
[ Info: Starting running test items
  Worker 56513:  15:57:53 | maxrss  0.5% | mem 59.5% | START (1/2) test item "use a test-only dep" at test/deps_tests.jl:1
  Worker 56513:  15:57:53 | maxrss  0.6% | mem 59.6% | DONE  (1/2) test item "use a test-only dep" 0.4 secs

No Captured Logs for test item "use a test-only dep" at test/deps_tests.jl:1 on worker 56513
Error in testset "use a test-only dep" on worker 56513:
Error During Test at /Users/nickr/repos/ReTestItems.jl/test/packages/TestOnlyDeps/test/deps_tests.jl:1
  Got exception outside of a @test
  ArgumentError: Package Example not found in current path.
  - Run `import Pkg; Pkg.add("Example")` to install the Example package.
  Stacktrace:
    [1] macro expansion
      @ ./loading.jl:1772 [inlined]
    [2] macro expansion
      @ ./lock.jl:349 [inlined]
    [3] __require(into::Module, mod::Symbol)
      @ Base ./loading.jl:1753
    [4] #invoke_in_world#2
      @ ./essentials.jl:926 [inlined]
    [5] invoke_in_world
      @ ./essentials.jl:923 [inlined]
    [6] require(into::Module, mod::Symbol)
      @ Base ./loading.jl:1746
    [7] eval
      @ ./boot.jl:403 [inlined]
    [8] #77
      @ ~/repos/ReTestItems.jl/src/ReTestItems.jl:1142 [inlined]
    [9] with_source_path(f::ReTestItems.var"#77#78"{Expr}, path::String)
      @ ReTestItems ~/repos/ReTestItems.jl/src/ReTestItems.jl:965
   [10] (::ReTestItems.var"#75#76"{TestItem, String, Expr, Expr})()
      @ ReTestItems ~/repos/ReTestItems.jl/src/ReTestItems.jl:1142
   [11] redirect_stdio(f::ReTestItems.var"#75#76"{TestItem, String, Expr, Expr}; stdin::Nothing, stderr::IOContext{IOStream}, stdout::IOContext{IOStream})
      @ Base ./stream.jl:1413
   [12] redirect_stdio
      @ ./stream.jl:1376 [inlined]
   [13] _redirect_logs(f::ReTestItems.var"#75#76"{TestItem, String, Expr, Expr}, target::IOStream)
      @ ReTestItems ~/repos/ReTestItems.jl/src/log_capture.jl:124
   [14] #_redirect_logs##0
      @ ~/repos/ReTestItems.jl/src/log_capture.jl:107 [inlined]
   [15] open(::ReTestItems.var"#_redirect_logs##0#_redirect_logs##1"{ReTestItems.var"#75#76"{TestItem, String, Expr, Expr}}, ::String, ::Vararg{String}; kwargs::@Kwargs{})
      @ Base ./io.jl:396
   [16] open
      @ ./io.jl:393 [inlined]
   [17] _redirect_logs
      @ ~/repos/ReTestItems.jl/src/log_capture.jl:107 [inlined]
   [18] macro expansion
      @ ~/repos/ReTestItems.jl/src/macros.jl:82 [inlined]
   [19] runtestitem(ti::TestItem, ctx::ReTestItems.TestContext; test_end_expr::Expr, logs::Symbol, verbose_results::Bool, finish_test::Bool, catch_test_error::Bool, failfast::Bool)
      @ ReTestItems ~/repos/ReTestItems.jl/src/ReTestItems.jl:1139
   [20] top-level scope
      @ none:1
   [21] eval
      @ ./boot.jl:403 [inlined]
   [22] execute
      @ ~/repos/ReTestItems.jl/src/workers.jl:334 [inlined]
   [23] (::ReTestItems.Workers.var"#serve_requests##0#serve_requests##1"{Sockets.TCPSocket, ReentrantLock, ReTestItems.Workers.Request})()
      @ ReTestItems.Workers ~/repos/ReTestItems.jl/src/workers.jl:348

  Worker 56513:  15:57:54 | maxrss  0.6% | mem 59.6% | START (2/2) test item "deps as expected" at test/deps_tests.jl:6
  Worker 56513:  15:57:54 | maxrss  0.6% | mem 59.6% | DONE  (2/2) test item "deps as expected" <0.1 secs (90.1% compile), 16.75 K allocs (1.283 MB)
[ Info: All tests on worker 1 completed. Closing Worker(pid=56513).
  Worker 56513:  [56513] signal (15): Terminated: 15
in expression starting at none:1

[ Tests Completed: 2/2 test items were run.
Test Summary:             | Pass  Error  Total  Time
TestOnlyDeps              |    1      1      2  3.0s
  test                    |    1      1      2
    test/deps_tests.jl    |    1      1      2
      use a test-only dep |           1      1  0.4s
      deps as expected    |    1             1  0.0s
ERROR: Some tests did not pass: 1 passed, 0 failed, 1 errored, 0 broken.
ERROR: failed process: Process(setenv(`/Users/nickr/repos/rai-julia/usr/bin/julia -C native -J/Users/nickr/repos/rai-julia/usr/lib/julia/sys.dylib -g1 --project=test/packages/TestOnlyDeps -e '
    using ReTestItems, TestOnlyDeps; runtests(TestOnlyDeps; nworkers=1)'`

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes issue #228 where test-only dependencies (specified in [extras] and [targets] sections of Project.toml) were not available on worker processes when running tests with nworkers > 0 and JULIA_PROJECT set.

Key changes:

  • Workers now explicitly activate the test environment by capturing and setting the active project on worker startup
  • Added comprehensive test package TestOnlyDeps.jl to verify test-only dependencies work correctly with workers

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

File Description
src/ReTestItems.jl Captures the active project and sets it on worker processes to ensure test environment is activated
test/integrationtests.jl Adds regression test for issue #228 that runs tests with workers and test-only deps
test/packages/TestOnlyDeps/* New test package demonstrating test-only dependency usage
test/packages/README.md Documents the new TestOnlyDeps.jl test package

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Collaborator

@Drvi Drvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@nickrobinson251 nickrobinson251 merged commit 0f3d119 into main Oct 28, 2025
5 of 9 checks passed
@nickrobinson251 nickrobinson251 deleted the npr-worker-testenv-fix branch October 28, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workers have incorrect environment when JULIA_PROJECT set

3 participants