uber / doubles

Test doubles for Python.
MIT License
164 stars 17 forks source link

Better generator support #56

Closed jordanlibrande closed 9 years ago

jordanlibrande commented 10 years ago

I would love if there was a nicer way to specify a series of return values for multiple calls to the same function than the following (best I've found).

object_a = object()
object_b = object()

def object_generator_function():
    yield object_a
    yield object_b

object_generator = object_generator_function()

allow(Foo).baz.and_return_result_of(lambda: next(object_generator))
toddsifleet commented 10 years ago

It looks like this feature is undocumented, but it should work to do:

 allow(Foo).baz.and_return(object_a, object_b)

The first call will return object_a, the second object_b, and every call after that object_b.

I will update the docs to include this.