Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Error while running in @safetestset #107

Closed
iskyd opened this issue Mar 9, 2023 · 6 comments
Closed

Bug: Error while running in @safetestset #107

iskyd opened this issue Mar 9, 2023 · 6 comments

Comments

@iskyd
Copy link

iskyd commented Mar 9, 2023

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:

@rofinn
Copy link
Collaborator

rofinn commented Mar 9, 2023

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?

@iskyd
Copy link
Author

iskyd commented Mar 9, 2023

@rofinn I got
LoadError: UndefVarError: Mocking not defined
and that happens on the line where I use Mocking.@patch, Mocking.activate works.

@rofinn
Copy link
Collaborator

rofinn commented Mar 9, 2023

Weird. Okay, if nobody gets to it I'll take a closer look in a few hours.

@iskyd
Copy link
Author

iskyd commented Mar 9, 2023

@rofinn I think that the problem is this: YingboMa/SafeTestsets.jl#3

@rofinn
Copy link
Collaborator

rofinn commented Mar 9, 2023

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

@omus
Copy link
Member

omus commented Jul 15, 2024

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: YingboMa/SafeTestsets.jl#16

@omus omus closed this as completed Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants