mockall icon indicating copy to clipboard operation
mockall copied to clipboard

How to bypass a mock for a particular test and call the original function

Open greg-kinasa opened this issue 1 year ago • 3 comments

I'm using automock on a mod and have some tests that I want to utilize the mock but others that should call through the original function implementations. Is there a way to have this happen directly without grabbing the original function and calling it from returning?

greg-kinasa avatar Apr 17 '24 20:04 greg-kinasa

There's nothing magic in automock. If you want to call the real function instead of the mock one, then make sure you call it through it's full path. i.e. don't call it through the path that uses mockall_double. Or if you want to use the mock in some test cases but not others for the same code, you'll have to call the real version from .returning.

asomers avatar Apr 17 '24 21:04 asomers

In my case the mocked function is within several layers of code and conditionally brought it by feature flag. I wouldn't be opposed to calling the original through .returning however it's async and after reading through existing issues it seems I'd have to change my function signatures to accommodate. Thanks for your prompt response.

greg-kinasa avatar Apr 17 '24 23:04 greg-kinasa

Is there anything else you need here?

asomers avatar Apr 28 '24 17:04 asomers