# Updating of variables inside testset

**URL:** <https://discourse.julialang.org/t/updating-of-variables-inside-testset/19755>\
**Category:** General Usage\
**Created:** [January 17, 2019, 6:45pm UTC](https://discourse.julialang.org/t/updating-of-variables-inside-testset/19755 "2019-01-17T18:45:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Post date:** [January 17, 2019, 6:45pm UTC](https://discourse.julialang.org/t/updating-of-variables-inside-testset/19755/1 "2019-01-17T18:45:00Z")

</div>

Hi everyone,

I encountered this problem already multiple times and I don’t understand the reason for this behaviour.

I don’t have a minimal working example, but the basic setup is the following:

```julia
@testset "FirstSet" begin
    a = 0.1
    b = 0.7
    @testset "SecondSet" begin
        .... Some transformations based on a and b
        .... Check that two different formulations are identical
        @test f(a,b) ≈ g(a,b)
    end
end

```

This works just fine. However, I would like to do the following, to make sure it works also for different values:

```julia
@testset "FirstSet" begin
    a = 0.1
    b = 0.7
    @testset "SecondSet" for a = 0.1:0.1:0.2, b = 0.7:0.1:0.8
        .... Some transformations based on a and b
        .... Check that two different formulations are identical
        @test f(a,b) ≈ g(a,b)
    end
end

```

Which fails four times. Indeed, even the following fails:

```julia
@testset "FirstSet" begin
    @testset "SecondSet" for a = 0.1, b = 0.7
        .... Some transformations based on a and b
        .... Check that two different formulations are identical
        @test f(a,b) ≈ g(a,b)
    end
end

```

Which is, according to my understand, identical to the first. It seems, however, that it isn’t. Can someone explain to me this behavior? I had this problem already a couple of times.

---

<div class="post-metadata">

**Author:** ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)\
**Post date:** [January 17, 2019, 6:58pm UTC](https://discourse.julialang.org/t/updating-of-variables-inside-testset/19755/2 "2019-01-17T18:58:42Z")

</div>

I managed to find the error. I had inside the second @testset the following statement

```julia
g_closure(x) = g(x, y = 1)
term1 = g_closure.(x)

g_closure(x) = g(x,y = 0)
term2 = g_closure.(x)

return term1 - term2

```

It seems that redefining `g_closure` does not work inside the ` begin...end` environment. However, the following works:

```julia
g_closure1(x) = g(x, y = 1)
term1 = g_closure1.(x)

g_closure2(x) = g(x,y = 0)
term2 = g_closure2.(x)

return term1 - term2

```

Can someone explain why the first example works in the REPL, but not inside a function?
