Module A
includes import B
at its top. However under test conditions I'd like to mock B
in A
(mock A.B
) and completely refrain from importing B
.
In fact, B
isn't installed in the test environment on purpose.
A
is the unit under test. I have to import A
with all its functionality. B
is the module I need to mock. But how can I mock B
within A
and stop A
from importing the real B
, if the first thing A
does is import B
?
(The reason B isn't installed is that I use pypy for quick testing and unfortunately B isn't compatible with pypy yet.)
How could this be done?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…