# Access variale between testsets

**URL:** <https://discourse.julialang.org/t/access-variale-between-testsets/57390>\
**Category:** General Usage\
**Created:** [March 17, 2021, 2:54pm UTC](https://discourse.julialang.org/t/access-variale-between-testsets/57390 "2021-03-17T14:54:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://discourse.julialang.org/u/Michal)\
**Post date:** [March 17, 2021, 2:54pm UTC](https://discourse.julialang.org/t/access-variale-between-testsets/57390/1 "2021-03-17T14:54:14Z")

</div>

How can I take result from first testset and use it in second testset?

```julia
global result = 0;

@time @testset verbose=true "Upload" begin
    println(result)

    result = 1
end

@time @testset verbose=true "Update" begin
    println(result)
end

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 17, 2021, 3:01pm UTC](https://discourse.julialang.org/t/access-variale-between-testsets/57390/2 "2021-03-17T15:01:02Z")

</div>

This is a common mistake–putting `global` _at global scope_ doesn’t do anything at all. That is, doing:

```julia
global result = 0

```

and

```julia
result = 0

```

at global scope do exactly the same thing.

Instead, you need to put `global` where you _set_ `result` in some local scope to tell Julia to set the global variable instead of creating a new local variable:

```julia
result = 0

@testset "a" begin
  global result # Now within this scope, `result` will refer to the global variable
  @test result == 0
  result = 1
end

@testset "b" begin
  @test result == 1
end

```

Note that you can avoid the `global` issue _and_ improve performance by using a ref instead:

```julia
const result = Ref(0)
 
@testset "a" begin
  @test result[] == 0
  result[] = 1
end

@testset "b" begin
  @test result[] == 1
end

```

---

<div class="post-metadata">

**Author:** ![Michal](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Michal](https://discourse.julialang.org/u/Michal)\
**Post date:** [March 17, 2021, 3:15pm UTC](https://discourse.julialang.org/t/access-variale-between-testsets/57390/3 "2021-03-17T15:15:56Z")

</div>

Thank you, I’ll use second solution.
