class MyClass(object): myattr = 1and you want to test the functionality of the class, but need to change the value of myattr from the default:
import mock import modulename with mock.patch.object(modulename.MyClass, "myattr", new=50): # do test stuff