Skip to content

Instantly share code, notes, and snippets.

@jlnwlf
Created December 22, 2014 08:47
Show Gist options
  • Save jlnwlf/3fda4e7d5d8af5152f23 to your computer and use it in GitHub Desktop.
Save jlnwlf/3fda4e7d5d8af5152f23 to your computer and use it in GitHub Desktop.
Mock base class (old style classes)
class A:
def method(self):
print "I do stuff..."
def uniquemethod(self):
print "I'm only in A"
from a import A
class B(A):
def method(self):
A.method(self)
print "But I can do some other stuff too !"
from mock import patch
with patch('b.A') as p:
from b import B
def testing(self):
print "outside"
p.method.side_effect = testing
test = B()
test.method()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment