jsatt / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Intercepting function or method calls #217

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'm pretty sure this is a feature request.

I'd like to be able to use 'patch' to intercept methods or functions, muck with 
their return values, then return the altered return values. I'm using intercept 
here as in AOP where you call the original method and give the mocker a chance 
to play with the return value before returning it to your unsuspecting code 
under test.

The purpose is to test functions that return complex and context-dependent 
results (say a big blob of JSON from a somewhat RESTful web service). I'd like 
to use mocking to test unusual return values that are difficult to induce when 
desired.

If I was less OCD, I could just mock the whole return value, but something 
tells me that will require frequent maintenance as the API evolves.

Thanks!

Original issue reported on code.google.com by christop...@gmail.com on 14 Nov 2013 at 2:03

GoogleCodeExporter commented 8 years ago

Original comment by fuzzyman on 14 Nov 2013 at 11:06

GoogleCodeExporter commented 8 years ago
The functionality that lets you intercept function/method calls is called 
"wraps". I don't know how well it supports modifying those return values 
through side_effect. I expect not. I would certainly be open for a discussion 
on how this could work and a patch to implement it.

Original comment by fuzzyman on 14 Nov 2013 at 11:07