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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -