How to patch a module's internal functions with mock?

后端 未结 4 1172
情书的邮戳
情书的邮戳 2021-02-01 05:15

By \"internal function\", I mean a function that is called from within the same module it is defined in.

I am using the mock library, specifically the patch decorators,

4条回答
  •  醉话见心
    2021-02-01 05:58

    another option is to explicitly call patch on the function:

    mock.patch('function_name')
    

    and to support both running directly or from py.test etc:

    mock.patch(__name__ + '.' + 'function_name')
    

提交回复
热议问题