asomers / mockall

A powerful mock object library for Rust
Apache License 2.0
1.5k stars 62 forks source link

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

Closed greg-kinasa closed 5 months ago

greg-kinasa commented 6 months ago

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?

asomers commented 6 months ago

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.

greg-kinasa commented 6 months ago

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.

asomers commented 5 months ago

Is there anything else you need here?