Any way to keep the original source clean?
Let's say I have a function that looks like this:
function do_something_useful(a, b, c)
d = @mock(first_part(a, b))
if @mock(second_part(c, d))
@mock(third_part())
else
@mock(forth_part())
end
end
As you can see, I have to put @mock everywhere if I want to be able to patch all of them. The trouble is that the code does not look clean anymore. Would it be possible to do something like:
@mockfuns first_part second_part third_part forth_path
@mock function do_something_useful(a, b, c)
d = first_part(a, b)
if second_part(c, d)
third_part()
else
forth_part()
end
end
An approach like the would be possible but would make the macro processing more complicated than it is now. Something that is being looking into is using Cassette.jl to avoid having to use the @mock macro at all. Unfortunately that approach can have some performance impacts when running tests.
An alternative that may work for you would be to just mock do_something_useful calls instead of mocking each function within.
Is the Cassette version still being worked on?
How bad is the performance impact? Depending on the use case, performance may or may not be a concern....
Should probably make I new Cassette based version. After the 0.7 changes
SimpleMock.jl is based on Cassettevand already works @tk3369
Maybe another option is to make the IDE hide the @mock(...) part of the code 😉
We did the experiment with Cassette some time ago at this point but unfortunately there was too much of a performance reduction in comparison to using the @mock macro: https://github.com/JuliaTesting/Mocking.jl/issues/53#issuecomment-572204715
Doing it with CassetteOverlays.jl could be a good solution. It shouldn't have any of the issues Cassette has.