不能使用unittest.patch模拟import语句

时间:2017-02-02 05:09:23

标签: python python-2.7 magicmock

我在函数中有一个import语句,我想用patch修改import语句,但是不能。

    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'

0 个答案:

没有答案