@testitem "foo" begin
A = 0
for i in 1:10
A += i
end
@test A == 55
end
This succeeds when running tests via pkg> test, but fails when running in VS Code’s test pane. Presumably because they differ about whether they create a new scope for each test?
Should this be considered a bug in whatever the test pane is using behind the scenes (part of the Julia Extension, I think?)? Or do test writers need to worry about scope problems like this, and sprinkle let and/or global declarations around? [I would advocate for not the latter.]
The following works for me whether I’m in the REPL (soft scope) or running it as a script julia foo.jl (hard scope), so I don’t see how soft-scoping is relevant here:
using Test
@testset "foo" begin
A = 0
for i in 1:10
A += i
end
@test A == 55
end
(The reason it works is that @testset wraps everything in a let block, which creates a new scope, so A is not a global variable.)
I do mean @testitem, as is used for TestItemRunner or ReTestItems; but more specifically in this post, the error happens in the VS Code testing pane, whose details I don’t understand very well (see this thread: How does the Testing pane work?).