Método para automatizar el reemplazo de un método en el código a comprobar.
class BaseTestEnvironment(unittest.IsolatedAsyncioTestCase):
def _patch_method(self):
async def new_method(arg_1: Any, *args: Any):
return "anything"
patcher = patch.object(
TheClass,
"the_method",
side_effect=new_method,
)
self._m_method = patcher.start()
self.addCleanup(patcher.stop)
Llamando desde cualquier test a self._patch_method
se realizará el patch del método TheClass.the_method
durante la ejecución del test.