python - How to mock an import - Stack Overflow
https://stackoverflow.com/questions/865804328.12.2011 · 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 …