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> 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
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?