Is there a way to handle test case names?

with @testset you can specify a set name
can the same be done with @test somehow? Maybe by creating own extension for test macro, if so how?

Background:
Sometimes I want to have sets but also name the individual test cases in a set to make it more verbose for other developers what is exactly tested (and whether the individual test case is normal case or corner case, and so on).

I would just use code comments for this. I mean… I don’t. But if I wanted to be more thorough I would.

EDIT: My reasoning is that while I often look at the runtests.jl for a package, I almost never actually run the tests and look at the output unless I am developing a package. In that case, I would have already looked at the test code anyways.

I am looking for a non-comment solution
as I want to see the test case names in the output of test run

You could wrap every test in a testset if that’s the end result you want. You could extend the @test macro for that like you suggested if that makes it simpler.

macro namedtest(name, test)
    esc(:(@testset $name begin @test $test end))
end
julia> @namedtest "test 1" 1 == 1
Test Summary: | Pass  Total
test 1        |    1      1

Note that nested testsets don’t print if they pass:

julia> @testset "a bunch of tests" begin
           @namedtest "test 1" 1 + 1 == 2
           @namedtest "test 2" 1 * 1 == 1
       end
Test Summary:    | Pass  Total
a bunch of tests |    2      2

So I don’t know if this will get you the effect you want either.

1 Like

It looks okay-ish

Test Summary:    | Pass  Total
a bunch of tests |    2      2
Test.DefaultTestSet("a bunch of tests", Any[Test.DefaultTestSet("test 1", Any[], 1, false, false), Test.DefaultTestSet("test 2", Any[], 1, false, false)], 0, false, false)

Test Summary:    | Pass  Fail  Total
a bunch of tests |    1     1      2
  test 1         |    1            1
  test 2         |          1      1
ERROR: Some tests did not pass: 1 passed, 1 failed, 0 errored, 0 broken.

Is the @testset my_func() functionality somewhat close to what you’re looking for? It’s been merged for a while, but I don’t know if it’s in a release yet. Possibly will only be released in 1.8.