# How to catch TestResult on failures?

**URL:** <https://discourse.julialang.org/t/how-to-catch-testresult-on-failures/128492>\
**Category:** General Usage\
**Tags:** testing\
**Created:** [April 28, 2025, 3:06pm UTC](https://discourse.julialang.org/t/how-to-catch-testresult-on-failures/128492 "2025-04-28T15:06:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)\
**Post date:** [April 28, 2025, 3:06pm UTC](https://discourse.julialang.org/t/how-to-catch-testresult-on-failures/128492/1 "2025-04-28T15:06:41Z")

</div>

I’m trying to grab the results after running tests, so I can send emails or slack messages based on the results.

However, if there are any failures, `@testset` does not return the test set:

```julia
julia> using OhMyREPL; using Test

julia> testset1 = @testset "Potato" begin @test 1 == 1; @test 2 == 2; end
Test Summary: | Pass Total Time
Potato | 2 2 0.3s
Test.DefaultTestSet("Potato", Any[], 2, false, false, true, 1.745852096930328e9, 1.745852097265343e9, false, "REPL[3]")

julia> testset2 = @testset "Potato2" begin @test 1 == 1; @test 2 == 3; end
Potato2: Test Failed at REPL[4]:1
  Expression: 2 == 3
   Evaluated: 2 == 3

Stacktrace:...

julia> testset1
Test.DefaultTestSet("Potato", Any[], 2, false, false, true, 1.745852096930328e9, 1.745852097265343e9, false, "REPL[3]")

julia> testset2
ERROR: UndefVarError: `testset2` not defined in `Main`
Suggestion: check for spelling errors or missing imports.

```

Because `finish(ts::DefaultTestSet)` throws if any tests failed: [julia/stdlib/Test/src/Test.jl at master · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/blob/master/stdlib/Test/src/Test.jl#L1331)

One way around this would be to define my own test type, and define all the methods to be the same except `finish`. But this seems a little excessive when I just want to get the testset. Is there any easier way to extract `testset2` even if there are failures?
