Ad-hoc stub methodsΒΆ

Create a standalone stub method directly over any instance (even no doubles), with method_returning() and method_raising():

from doublex import method_returning, method_raising, assert_that

collaborator = Collaborator()
collaborator.foo = method_returning("bye")
assert_that(collaborator.foo(), is_("bye"))

collaborator.foo = method_raising(SomeException)
collaborator.foo()  # raises SomeException



Traceback (most recent call last):
...
SomeException