Quantcast
Channel: Python Mock object with method called multiple times - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by k.parnell for Python Mock object with method called multiple times

$
0
0

Try side_effect

def my_side_effect(*args, **kwargs):
    if args[0] == 42:
        return "Called with 42"
    elif args[0] == 43:
        return "Called with 43"
    elif kwarg['foo'] == 7:
        return "Foo is seven"

mockobj.mockmethod.side_effect = my_side_effect

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>