The following reports Cannot define function ; it already has a value. in the line marked with a comment. But running the code works fine because, as the Note box here says, @testset creates a new scope. There is no warning when writing f(x) = 1 instead of the anonymous function in the first block.
using Test
@testset "1" begin
f = x -> 1
f(1)
end
@testset "2" begin
f(x) = 2 # <- warning here
f(2)
end
The following reports
Cannot define function ; it already has a value.
in the line marked with a comment. But running the code works fine because, as the Note box here says,@testset
creates a new scope. There is no warning when writingf(x) = 1
instead of the anonymous function in the first block.