'Is it possible to patch/mock internal function inside another function with unittest in python

Looks like it is impossible, but I'll try to ask...

Let's say I have this function:

def something(x)

  def subsomething(x):
    return 'a' if x == 1 else 'b'

  message = f'the character is {subsomething(x)}'
  return message

Is it possible to patch subsomething's return value and set it to c without changing something?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source