use mock in python to return instead of raising exception?

Viewed 112

This is what I plan to do:

def foo(flag):
    """
    other irrelevant code
    """
    if flag:
        import random
        return random.random()
    """
    other irrelevant code
    """
    raise Exception()

I know mock can be used to change the behavior of class or function, but not sure how it can be used to return instead of raising exception.

I am wondering if there is any way mock can change this raise into return something, without affecting the other code

1 Answers
Related