# @test return is not what the docs say it is

**URL:** <https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396>\
**Category:** Internals & Design\
**Tags:** question, documentation, testing\
**Created:** [April 28, 2020, 8:27pm UTC](https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396 "2020-04-28T20:27:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsweber2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dsweber2/32/3606_2.png) [@dsweber2](https://discourse.julialang.org/u/dsweber2)\
**Post date:** [April 28, 2020, 8:27pm UTC](https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396/1 "2020-04-28T20:27:23Z")

</div>

[The documentation](https://docs.julialang.org/en/v1/stdlib/Test/#Test.@test) for @test suggests that if the expression returns either true of false, you should get back either Test.Pass or Test.Fail. However, running simply `foo = @test false` in the repl causes and error (so `foo` isn’t actually defined), and running it in a test set:

```julia
@testset "foo" begin
           thing = @test false
           println(typeof(thing))
end

```

Gives a `Tuple{Test.Fail,Array{Union{Ptr{Nothing}, Base.InterpreterIP},1}}`. So it seems there’s a discrepancy between the documentation and the actual behavior.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [April 28, 2020, 10:18pm UTC](https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396/3 "2020-04-28T22:18:23Z")

</div>

I guess the use of the word “returns” is in error, it probably should say “prints”. Is there something specific you want to do? If you need the result of a previous test so the following tests only execute under a successful situation you can do:

```julia
@testset "foo" being
    thing = false
    @test thing = ....
    if thing == true
         # additional tests
    end
end
```

---

<div class="post-metadata">

**Author:** ![dsweber2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dsweber2/32/3606_2.png) [@dsweber2](https://discourse.julialang.org/u/dsweber2)\
**Post date:** [April 28, 2020, 10:57pm UTC](https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396/4 "2020-04-28T22:57:18Z")

</div>

I’m putting several tests inside of a for loop, and I would like to know for which values of the iteration the tests fail. Your suggested workaround will definitely work for me

```julia
@testset "foo" being
    for ii=1:10
      thing = false
      someResult = functionOfII(ii)
      @test thing = ...# compare someResult to something else
      if !thing
            # print the value of ii
      end
    end
end

```

---

<div class="post-metadata">

**Author:** ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)\
**Post date:** [April 28, 2020, 11:54pm UTC](https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396/5 "2020-04-28T23:54:37Z")

</div>

If you’re not doing anything other than printing the result, you can get a similar effect by nesting testsets. E.g.

```julia
@testset "foo" for i in 1:10
    @testset "Test $i" begin
        @test iseven(i)
    end 
end

```

---

<div class="post-metadata">

**Author:** ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)\
**Post date:** [April 29, 2020, 12:02pm UTC](https://discourse.julialang.org/t/test-return-is-not-what-the-docs-say-it-is/38396/6 "2020-04-29T12:02:59Z")

</div>

Nesting is not actually necessary. You can do

```julia
@testset "foo $i" for i in 1:10
        @test iseven(i)
end

```

I think nesting is more useful the other way around (`for` loop in the inside testset):

```julia
@testset "foo" begin
    @testset "Test $i" for i in 2:2:10
        @test iseven(i)
    end 
end

```

This way, if all tests succeed the summary is in one line, and if a test fails you still know which one.
