Debugger doesn't stop at breakpoints when running tests (but does during normal execution)

Julia 1.7.3
VS Code 1.74.3
Julia extension 1.38.2

I’m having a problem where, when I run tests with the debugger on the program I’m working on, the debugger doesn’t stop at any breakpoints I set. If I run the program normally (meaning executing a main function) with the debugger, the debugger works as expected and stops. I tried isolating the problem with a small example problem I can share here, however I can’t get the problem to reproduce in the example. Until I do, I suppose my question is which things in particular might be causing this issue and what I should look into.

Example

In the following the example and how I use it. I think it captures the structure and use of the full program well, but evidently I’m missing something.

project_dir
|> deps
  |> build.jl (empty)
|> src
  |> ModuleToTest.jl
  |> PackageToTest.jl
|> test
  |> runtests.jl
|> Manifest.toml
|> Project.toml

ModuleToTest.jl

module ModuleToTest

export do_something

function internal_only(x)
    return x + 1
end

function do_something(x)
    result = internal_only(x)
    return result
end

end

PackageToTest.jl

module PackageToTest

include("ModuleToTest.jl")
using .ModuleToTest

function main()
    print("The magic number is $(ModuleToTest.do_something(41))")
end
main()

end

runtests.jl

using Test
using PackageToTest.ModuleToTest

@testset "tests_are_working" begin
    @test true
end

@testset "test_do_something" begin
    @test ModuleToTest.do_something(41) == 42
end

@testset "test_internal_only" begin
    @test ModuleToTest.internal_only(41) == 42
end

Project.toml

name = "PackageToTest"
uuid = "2e0f99b1-0d8f-4296-8d0c-1c50a50d04c8"
authors = ["author"]
version = "0.1.0"

[deps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Running the example

For debugging the program and testing it I have two debugger settings in launch.json:

{
    "type": "julia",
    "request": "launch",
    "name": "Run file",
    "program": "project_dir/src/PackageToTest.jl",
    "stopOnEntry": false,
    "cwd": "project_dir/",
    "juliaEnv": "${command:activeJuliaEnvironment}",
    "args": []
},
{
    "type": "julia",
    "request": "launch",
    "name": "Run tests",
    "program": "project_dir/test/runtests.jl",
    "stopOnEntry": false,
    "cwd": "project_dir/",
    "juliaEnv": ".",
    "args": []
}

The launch config Run file runs the program with its main function, and will stop at breakpoints. Launching with Run tests will stop at breakpoints in this example, but not in the full project. I don’t use the REPL other than to add dependencies to Project.toml. Running tests from the PKG REPL, by activate . then test PackageToTest, runs the tests and works as normal, but I haven’t figured out how to use the debugger in the REPL for tests.

An update to our problem. It’s not solved, but I do have a new avenue to pursue. Let’s change the example by moving tests into other files that are being included:

runtests.jl

using Test

@testset "tests_are_working" begin
    @test true
end

include("included_tests.jl")

included_tests.jl

using PackageToTest.ModuleToTest

@testset "test_do_something" begin
    @test ModuleToTest.do_something(41) == 42
end

@testset "test_internal_only" begin
    @test ModuleToTest.internal_only(41) == 42
end

With this modification the example reproduces our problem. With launch config Run tests, the debugger will stop at breakpoints in file runtests.jl but not at breakpoints in any other file that is on the code path of tests, e.g. ModuleToTest.jl or included_tests.jl.

This is now beginning to sound similar to problems other users have found and solved, so I’m hoping I will stumble over a solution there.