Skip to content

Comments

Restore the working project after running user code.#93

Draft
maleadt wants to merge 1 commit intomainfrom
tb/active_project
Draft

Restore the working project after running user code.#93
maleadt wants to merge 1 commit intomainfrom
tb/active_project

Conversation

@maleadt
Copy link
Collaborator

@maleadt maleadt commented Feb 23, 2026

Otherwise the runner is broken after a test switches projects:

using ParallelTestRunner
using Test

testsuite = Dict(
    "first test" => quote
        using Pkg
        Pkg.activate(; temp=true)
        @test 1 + 1 == 2
    end,
    "second test" => quote
        @test 2 * 2 == 4
    end
)

runtests(ParallelTestRunner, ["--verbose", "--jobs=1"]; testsuite)
                  │          │ ──────────────── CPU ──────────────── │
Test     (Worker) │ Time (s) │ GC (s) │ GC % │ Alloc (MB) │ RSS (MB) │
first test    (1) │        started at 2026-02-23T10:26:32.874
first test    (1) │     0.21 │   0.00 │  0.0 │      30.71 │   378.98 │
second test   (1) │        started at 2026-02-23T10:26:34.700
second test   (1) |         crashed at 2026-02-23T10:26:35.219

Output generated during execution of 'first test':
┌ Precompiling packages...
│     502.1 ms  ✓ ParallelTestRunner
│   1 dependency successfully precompiled in 1 seconds. 35 already precompiled.
└   Activating new project at `/var/folders/wc/z_cydqs118735x03cvsf96tr0000gn/T/jl_5Vo7BU`

Test Summary:   | Pass  Error  Total  Time
  Overall       |    1      1      2  5.2s
    first test  |    1             1  0.2s
    second test |           1      1  0.5s
    FAILURE

Error in testset second test:
Error During Test at none:1
  Got exception outside of a @test
  Remote exception from Malt.Worker on port 9179 with PID 42179:
  
  ArgumentError: Package ParallelTestRunner not found in current path, maybe you meant `import/using .ParallelTestRunner`.
  - Otherwise, run `import Pkg; Pkg.add("ParallelTestRunner")` to install the ParallelTestRunner package.
  Stacktrace:
   [1] macro expansion
     @ ./loading.jl:2403 [inlined]
   [2] macro expansion
     @ ./lock.jl:376 [inlined]
   [3] __require(into::Module, mod::Symbol)
     @ Base ./loading.jl:2386
   [4] require(into::Module, mod::Symbol)
     @ Base ./loading.jl:2362
   [5] eval(m::Module, e::Any)
     @ Core ./boot.jl:489
   [6] (::var"#handle##0#handle##1"{Sockets.TCPSocket, UInt64, Bool, @Kwargs{}, Tuple{Module, Expr}, typeof(Core.eval)})()
     @ Main ~/.julia/packages/Malt/yA40d/src/worker.jl:120
ERROR: LoadError: Test run finished with errors
in expression starting at /Users/tim/Julia/pkg/ParallelTestRunner/wip.jl:15

Also add workspace entries for 1.12.

@vchuravy
Copy link
Member

Hm, elsewhere (as an example in Base) it is the responsibility of the party modifying the state to reset it.

function precompile_test_harness(@nospecialize(f), testset::String)
    @testset "$testset" precompile_test_harness(f, true)
end
function precompile_test_harness(@nospecialize(f), separate::Bool=true)
    load_path = mkdepottempdir()
    load_cache_path = separate ? mkdepottempdir() : load_path
    try
        pushfirst!(LOAD_PATH, load_path)
        pushfirst!(DEPOT_PATH, load_cache_path)
        f(load_path)
    finally
        filter!((≠)(load_path), LOAD_PATH)
        separate && filter!((≠)(load_cache_path), DEPOT_PATH)
    end
    return nothing
end

Beside the active project, there is also depot path and load path

@maleadt
Copy link
Collaborator Author

maleadt commented Feb 23, 2026

So the use case here is running examples, which often start with a Pkg.activate(@__DIR__). I guess I could add this to my harness executing examples, but it seemed reasonable to make ParallelTestRunner more robust to that.

@maleadt maleadt marked this pull request as draft February 23, 2026 10:08
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.

2 participants