Base.@kwdef breaks in tests only

I believe that’s unfortunately a case of this known issue: https://github.com/JuliaLang/julia/issues/9498
Basically the issue is that if you define

foo(; bar) = bar
foo() = 1

then you will get the expected

julia> foo()
1

However, if you try to reverse the order of definitions in a new julia session:

foo() = 1
foo(; bar) = bar

then you get

julia> foo()
ERROR: UndefKeywordError: keyword argument bar not assigned

In particular, in your program, the order of method definitions for Foo is well-defined, but I don’t think there is any guarantee that the order is preserved post-precompilation, which likely results in the issue you observe when testing it: the Foo() = Foo(bar=1) method gets virtually defined before the main constructor for Foo, which “shadows” it, if that makes sense.
What makes me think precompilation is the issue is that adding a __precompile__(false) statement at the beginning of your module definition removes the error as well, but this statement is not meant to solve this kind of issue at all so I would recommend against using it.

What I can recommend instead is simply adding the default value for bar in your constructor:

module Example

Base.@kwdef mutable struct Foo
    bar::Integer=1 # notice the =1
end

instance = Foo()
print("Instance value is $(instance.bar)")

end

Isn’t this the behavior what you were looking for? Otherwise, I’m afraid the simplest solution is getting rid of the Base.@kwdef and just create one big constructor method taking the relevant keyword arguments and setting the default “by hand”…