You should put your files inside separate modules, to sandbox them properly. That way, there is no contamiation between them, and the test function is not overwritten. You can either put the module declaration explicitly in your test files, or in the load code, e.g.:
sources = filter(endswith(".jl"), readdir("tests"; join = true))
for file in sources
module_name = gensym("mod_$file")
@eval module $module_name
function test end # prevent defining test something else as a function
include($file)
end
println(getfield(@__MODULE__, module_name).test())
end
Thanks again for your help. I think it’s time to ask a new question: How can I pipeline my test code without contamination between different code files?
I’m not sure that I understand the question. The code I wrote above puts each file in its own module, effectively preventing contamination. What exactly do you mean by pipelining your test code?
I should have explained the details. The questions I’m asking here are simplified. My actual code is much more complex and involves multiple module and function calls, some of which are even multi-threaded. Unfortunately, I am not familiar with sandbox and not sure which should be written inside the separate module.
I think I should raise a new question about it. or ask if there are any documents that can help me.
your code is really helpful but I need to understand and modify it further.