是否有任何可能伪造模块,这是由我在测试中使用的其他模块使用(导入)?其他模块使用的假模块
举例: 这是我的test.py:
import unittest
import module1
//test code here
module1.some_method()
//test code here
这是module1.py:
import module_i_want_to_fake
//module code here
基于例如:问题是:如何在测试我可以假module_i_want_to_fake
。 py
是什么原因?你可以'将module1导入为m1'或者使用其他名称作为参考。 – ninMonkey 2013-03-13 20:42:41
但是当我导入module1时,module1会导入module_i_want_to_fake,但我想导入my_fake_module – 2013-03-13 20:47:06
因此,您希望从'module1'之外拦截其“import”语句,以便您可以替换不同的模块? – abarnert 2013-03-13 20:47:42