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: @patch does not work when Mocking is not in scope #103

Closed
lklein-btig opened this issue Feb 23, 2023 · 2 comments
Closed

Bug: @patch does not work when Mocking is not in scope #103

lklein-btig opened this issue Feb 23, 2023 · 2 comments

Comments

@lklein-btig
Copy link

julia> using Mocking: @patch

julia> f() = 5
f (generic function with 1 method)

julia> f_patch = @patch f() = 6
ERROR: UndefVarError: Mocking not defined
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

The @patch macro expects Mocking to be in scope, which does not need to be the case.
The Blue style guide recommends putting things into scope as is done in the code snippet above for example.

@rofinn
Copy link
Collaborator

rofinn commented Mar 9, 2023

Hmm, that's tricky. Since @patch is just generating code that uses the Mocking namespace it is in scope as far as Julia is concern, so the correct way to write that according to the Blue style guide is:

using Mocking: Mocking, @patch
...

Outside of getting rid of the macro altogether I don't think there's a good solution.

@omus
Copy link
Member

omus commented Jul 15, 2024

This was fixed in #113 and included in v0.7.8

Example:

julia> using Mocking: @patch

julia> f() = 5
f (generic function with 1 method)

julia> f_patch = @patch f() = 6
Mocking.Patch{typeof(f)}(f, var"##f_patch#225")

julia> using Mocking: @mock, activate, apply

julia> activate()

julia> apply(f_patch) do
           @mock f()
       end
6

@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