1

我在函数中有一个导入语句,我想使用补丁模拟该导入语句,但不能。

    class A():
      """mock object"""
      @staticmethod
      def run():
        print('ran')

    @patch('something')
    def test_run(self, something):
      something = A()

      # my function has this statement
      from something import run

      run(....)

得到

    E   TypeError: Need a valid target to patch. You supplied: 'something'
4

0 回答 0