Patch ignored on v0.7.4
Closed this issue · 11 comments
A patch that was working just fine on v0.7.3 recently started being ignored on v0.7.4.
# mock report patch so that we don't repeatedly initiate the analysis environment
report_patch = @patch function generate_report(checkpoint_dir, save_dir)
return push!(empty!(report_path), checkpoint_dir, save_dir)
end
mktempdir() do dir
cd(dir) do
apply(report_patch) do # the patch fails to activate here
@test_deprecated(
conclude_backrun(pwd(), dates, results, actions; checkpoint_dir)
)
end
end
end
Now fails with:
conclude_backrun: Error During Test at /builds/invenia/Backruns.jl/test/deprecated.jl:38
Test threw exception
Expression: $(Expr(:escape, :(conclude_backrun(pwd(), dates, results, actions; checkpoint_dir))))
ArgumentError: analysis.jl not found in /tmp/jl_HV0qZ8
Stacktrace:
[1] generate_report(script_dir::String, output_dir::FilePathsBase.PosixPath; script_name::String)
@ Backruns /builds/invenia/Backruns.jl/src/reporting.jl:195
[2] generate_report
@ /builds/invenia/Backruns.jl/src/reporting.jl:193 [inlined]
[3] macro expansion
@ ~/.julia/packages/Mocking/gg4Vm/src/mock.jl:26 [inlined]
Strangely switching the order of nesting seems to fix the problem:
mktempdir() do dir
cd(dir) do
@test_deprecated(
apply(report_patch) do # the patch succeeds here
conclude_backrun(pwd(), dates, results, actions; checkpoint_dir)
end
)
end
end
My attempts to create a simpler MWE by combining apply
and @test_deprecate
have failed so I'm not sure what the cause might be.
@morris25 are you relying on patching the behaviour of an @async
task which was spawned outside the context of the apply
block? If so that would be the problem
I've managed to reproduce the problem with using julia --depwarn=yes
and:
using Mocking, Test
Mocking.activate()
f() = "original"
Base.@deprecate generate_report() f()
report_patch = @patch generate_report() = "mocked"
apply(report_patch) do # the patch fails to activate here
@test_deprecated(
(@mock generate_report())
)
end
Thanks @omus! Sorry for the late reply, I had to run off for the long weekend.
are you relying on patching the behaviour of an @async task which was spawned outside the context of the apply block? If so that would be the problem
There is no async code involved in the test. It appears that my problem creating the MWE was simply forgetting to set the depwarn flag.
The Mocking.jl version has now been pinned in numerous internal packages to avoid this issue in v0.7.4 -- is there anyone working on a fix?
The Mocking.jl version has now been pinned in numerous internal packages to avoid this issue in v0.7.4 -- is there anyone working on a fix?
I'll be looking into the source of this MWE today or tomorrow.
Problem is specific to using ContextVariablesX.jl: tkf/ContextVariablesX.jl#16
As there appears to be no path forward to fixing ContextVariablesX.jl I'll opt to instead revert the changes in #91 and yank the 0.7.4 release
Better MWE:
using Mocking, Test
Mocking.activate()
generate_report() = "original"
report_patch = @patch generate_report() = "mocked"
apply(report_patch) do
@test (@test_logs @mock generate_report()) == "mocked" # returns "original"
end
Yanking 0.7.4 here: JuliaRegistries/General#46759
Note that ScopedValues.jl package (not the implemention in Base
with Julia 1.11) has the same issue as ContextVariablesX.jl did.