Bug: Error while running in @safetestset
runtests.jl
cd(@__DIR__)
using Pkg
using Test, TestSetExtensions, SafeTestsets
@testset ExtendedTestSet "Example tests" begin
@includetests ARGS
end
test.jl
@safetestset "test" begin
using Mocking
Mocking.activate()
patch = @patch open(fn::Function, f::AbstractString) = fn(IOBuffer(data))
end
This throws LoadError: UndefVarError: @patch not defined
Julia version: 1.8.2 Operating System: Ubuntu 22.04 Mocking version:
Hmm, does Mocking.@patch work since Mocking.activate() seems to be working? I wonder if something weird is happening with the export @patch inside the @safetestset macro?
@rofinn I got LoadError: UndefVarError: Mocking not defined and that happens on the line where I use Mocking.@patch, Mocking.activate works.
Weird. Okay, if nobody gets to it I'll take a closer look in a few hours.
@rofinn I think that the problem is this: https://github.com/YingboMa/SafeTestsets.jl/issues/3
Ah, that makes sense. I don't think there's much we can do on the Mocking.jl side then, but we might be able to work around it for your case. If you're willing to manually construct the Mocking.Patch object instead of using @patch to parse the expression then that should work.
https://github.com/JuliaTesting/Mocking.jl/blob/master/src/patch.jl#L2
The workaround in SafeTestsets.jl is to use an include in your @safetestset and utilize the using Mocking from within the included file.
Overall, this is an issue with SafeTestsets.jl and I've made a PR to allow the original example to work in: https://github.com/YingboMa/SafeTestsets.jl/pull/16