# Providing @testset option with macro depending on Julia version

**URL:** <https://discourse.julialang.org/t/providing-testset-option-with-macro-depending-on-julia-version/105689>\
**Category:** General Usage\
**Tags:** macros\
**Created:** [November 2, 2023, 11:00am UTC](https://discourse.julialang.org/t/providing-testset-option-with-macro-depending-on-julia-version/105689 "2023-11-02T11:00:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnHeuermann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/anheuermann/32/27059_2.png) [@AnHeuermann](https://discourse.julialang.org/u/AnHeuermann)\
**Post date:** [November 2, 2023, 11:00am UTC](https://discourse.julialang.org/t/providing-testset-option-with-macro-depending-on-julia-version/105689/1 "2023-11-02T11:00:17Z")

</div>

I want to use Test.@testset with option `failfast=true` in my unit testing. But this feature requires at least Julia 1.9 and I’m testing on both newer and older versions of Julia.

I would like to define a macro or function that checks the Julia version and only sets `failfast` if the version is above 1.9.

My best guess so far:

```julia
using Test

macro failfast()
  @static if Base.VERSION ≥ v"1.9"
    :( failfast=true )
  end
end

@testset verbose=false @failfast "MyTest" begin
  @test true
end

```

How do I prevent that the macro expression is executed immediately?  
I also tried the use of code generation with `@eval`, but without success.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [November 4, 2023, 6:57am UTC](https://discourse.julialang.org/t/providing-testset-option-with-macro-depending-on-julia-version/105689/2 "2023-11-04T06:57:08Z")

</div>

I don’t think this is the correct approach as the macro-expansion order is probably always wrong (depends a bit on how `@testset` uses the option). You’ll need to put a macro infront like

```julia
macro mytestset(body)
    quote
        if Base.VERSION ≥ v"1.9"
            @testset verbose=false failfast=true begin $body end
        else
            @testset verbose=false begin $body end
        end
    end
end

```

You can also extend this to take keyword arguments and forward them to `@testset` and then it almost looks like the regular macro 🙂  
(Coded on mobile so syntax might be off. I am not sure if you need the `begin` `end` around `$body` but shouldn’t hurt)
