-
-
Save jlnwlf/3fda4e7d5d8af5152f23 to your computer and use it in GitHub Desktop.
Mock base class (old style classes)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A: | |
def method(self): | |
print "I do stuff..." | |
def uniquemethod(self): | |
print "I'm only in A" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from a import A | |
class B(A): | |
def method(self): | |
A.method(self) | |
print "But I can do some other stuff too !" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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