# Bug in @testset with @test\_throws?

**URL:** <https://discourse.julialang.org/t/bug-in-testset-with-test-throws/7213>\
**Category:** General Usage\
**Tags:** question, testing\
**Created:** [November 21, 2017, 4:53am UTC](https://discourse.julialang.org/t/bug-in-testset-with-test-throws/7213 "2017-11-21T04:53:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjb](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cjb](https://discourse.julialang.org/u/cjb)\
**Post date:** [November 21, 2017, 4:53am UTC](https://discourse.julialang.org/t/bug-in-testset-with-test-throws/7213/1 "2017-11-21T04:53:20Z")

</div>

Writing some tests yesterday I discovered the following weird behavior difference between a test inside and outside a @testset. This seems to be the case when returning a type (in this case Void) from the function being tested.

I realized I was making a mistake and should return `nothing` instead, but I think still the two tests should pass in this case, or I’m misunderstanding something. This is in Julia v0.6.1 and also in the latest v0.5:

```julia
function someFunction(vec::Vector{String})
    @assert length(vec) > 1 "Vector too small"

    # yes, I know this is a bit weird here
    return Void
end

using Base.Test

@testset "Some test set" begin
    # this will fail and say it didn't throw
    @test_throws AssertionError someFunction(String[])
end

# this test will pass
@test_throws AssertionError someFunction(String[])

```

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 21, 2017, 7:47am UTC](https://discourse.julialang.org/t/bug-in-testset-with-test-throws/7213/2 "2017-11-21T07:47:55Z")

</div>

Simpler repro:

```julia
using Base.Test

foo() = (assert(false); return Void)

@test_throws AssertionError foo()

@testset begin @test_throws AssertionError foo() end

```

It seems like it is connected to `return Void` because if I change that to e.g. `return nothing` the failure goes away. Note also that this is working as expected on the master branch.

Also, do you want to return `Void` ([the type](https://docs.julialang.org/en/latest/stdlib/base/#Core.Void))? Usually one returns `nothing` ([the instance](https://docs.julialang.org/en/latest/stdlib/constants/#Core.nothing)) instead.

---

<div class="post-metadata">

**Author:** ![cjb](https://avatars.discourse-cdn.com/v4/letter/c/a4c791/32.png) [@cjb](https://discourse.julialang.org/u/cjb)\
**Post date:** [November 21, 2017, 7:55am UTC](https://discourse.julialang.org/t/bug-in-testset-with-test-throws/7213/3 "2017-11-21T07:55:49Z")

</div>

Exactly, if an instance is returned (`nothing`) then it’s alright. I am planning to return the instance but I still wanted to report the ‘bug’.  
Is master v0.7? Then I guess it’s not very critical, except if anyone finds this important to be backported. Thanks.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 21, 2017, 8:01am UTC](https://discourse.julialang.org/t/bug-in-testset-with-test-throws/7213/4 "2017-11-21T08:01:14Z")

</div>

> [@cjb](#):
>
> Is master v0.7?

Yes.

> [@cjb](#):
>
> Then I guess it’s not very critical, except if anyone finds this important to be backported.

If you (or anyone else) finds the commit that fixed this it could potentially be backported.
