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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -