python - How to mock.patch a class imported in another module -


i have python class such module:

xy.py

from a.b import classa  class classb:   def method_1():     = classa()     a.method2() 

then have classa defined as:

b.py

from c import classc  class classa:   def method2():       c = classc()       c.method3() 

now in code, when writing test xy.py want mock.patch classc, there way achieve in python?

obviously tried:

mock.patch('a.b.classa.classc) 

and

mock.patch('a.b.c.classc') 

none of these worked.

you need patch classc located that's classc in b:

mock.patch('b.classc') 

or, in other words, classc imported module b , that's scope in classc needs patched.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -