# Preventing test error behavior

**URL:** https://discourse.julialang.org/t/preventing-test-error-behavior/127460
**Category:** General Usage
**Tags:** testing
**Created:** [March 28, 2025, 3:18pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460 "2025-03-28T15:18:03Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Marco\_Antoniotti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco_antoniotti/32/18697_2.png) [@Marco\_Antoniotti](https://discourse.julialang.org/u/Marco_Antoniotti)
#### Post date: [March 28, 2025, 3:18pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/1 "2025-03-28T15:18:03Z")

</div>

Hi

Question about `Test` and its use; this is my setup.

I have a `runtests.jl` file containing `@test`’s and `@testset`’s. I load it from the shell (don’t ask; that’s what I need and want).

```julia
$ julia -e 'include(sometests/runtests.jl)'

```

How do I prevent the `@test` macros from generating errors and stopping? This seems possible using `Base.runtests`, but when do you call it? Also, wrapping everything in a `@testset` seem to break the subtests data (passed, failed, etc) collection.

Any ideas?

Thanks

Marco

---

<div class="post-metadata">

### Author: ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)
#### Post date: [March 28, 2025, 4:44pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/2 "2025-03-28T16:44:25Z")

</div>

You need to wrap `@test` in a `@testset` to prevent it from stopping the script, e.g.:

```julia
using Test

@testset "Test1" begin
    @test 0 == 1
    @test 1 == 2
end

```

For me to help you with the breaking subtests issue you will need to post a minimal example of a Julia file that does this.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [March 28, 2025, 5:46pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/3 "2025-03-28T17:46:35Z")

</div>

> [@Marco\_Antoniotti](#):
>
> Also, wrapping everything in a `@testset` seem to break the subtests data (passed, failed, etc) collection.

That definitely shouldn’t happen, I’m using that nesting everywhere - do you have an example showing this?

---

<div class="post-metadata">

### Author: ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)
#### Post date: [March 28, 2025, 9:11pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/4 "2025-03-28T21:11:24Z")

</div>

> [@Marco\_Antoniotti](#):
>
> Also, wrapping everything in a `@testset` seem to break the subtests data (passed, failed, etc) collection.

Sometimes wrapping too much in a `@testset` can cause subtle errors because the `@testset` introduces an implicit local scope. It’s usually best to make sure any top level definitions like `struct` definitions or function definitions are not put inside a `@testset`.

> [@Marco\_Antoniotti](#):
>
> seem to break the subtests data (passed, failed, etc) collection

If you’re referring to the `@testset` not showing the individual test results, that’s normal when all the individual `@test` results pass. If one or more `@test` fails, then the `@testset` will print out a more detailed list of what passed and what failed.

---

<div class="post-metadata">

### Author: ![Marco\_Antoniotti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco_antoniotti/32/18697_2.png) [@Marco\_Antoniotti](https://discourse.julialang.org/u/Marco_Antoniotti)
#### Post date: [March 29, 2025, 6:43pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/5 "2025-03-29T18:43:29Z")

</div>

Thank you.

I feel I have figured out most of the idiosyncrasies of the Test package.

Let’s just say I was probably expecting something different.

First of all, I expected that the `@test` macro always printed what happened (having control about it). Secondly, I am writing a specialized test set type in order to gather results and do some computations with them, however, it is unclear (to me) how the nesting behavior works. Finally, why is there the `Base.runtests` function, if including a file with tests just runs them?

Apologies for the rant, but I am starting to think that a different testing framework would be nice. No, I do not have time to cook up one 😏

All the best

MA

---

<div class="post-metadata">

### Author: ![GHTaarn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ghtaarn/32/216007_2.png) [@GHTaarn](https://discourse.julialang.org/u/GHTaarn)
#### Post date: [March 29, 2025, 8:02pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/6 "2025-03-29T20:02:22Z")

</div>

My advice to you would be to start off by reading [the `Test` manual](https://docs.julialang.org/en/v1/stdlib/Test/), try to be flexible and open to doing things in the standard way - maybe try it out a bit for yourself. A lot of us are happy with just using the `Test` standard library, but if you know that this is completely unacceptable to you, there are packages in the `General` registry that might be able to provide what you want, but doing things in a non-standard way has a price.

> [@Marco\_Antoniotti](#):
>
> ```julia
> $ julia -e 'include(sometests/runtests.jl)'
> 
> ```

The standard place to put tests is in the “test” directory. Do you have a good reason to do something non-standard?

---

<div class="post-metadata">

### Author: ![Marco\_Antoniotti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco_antoniotti/32/18697_2.png) [@Marco\_Antoniotti](https://discourse.julialang.org/u/Marco_Antoniotti)
#### Post date: [March 29, 2025, 8:50pm UTC](https://discourse.julialang.org/t/preventing-test-error-behavior/127460/7 "2025-03-29T20:50:33Z")

</div>

Yes. I have a relatively good reason for doing things in a “non standard” way. Even if this means peppering tests and testsets  
with `println` and `@show`.

Having said that, it has been know for “standards” to improve over time.  
I am old enough to have been a witness to many such events.
