Skip to content

Instantly share code, notes, and snippets.

@hjwp hjwp/
Created Aug 13, 2014

What would you like to do?
example of testing super calls
x = None
class Parent:
def foo(self):
return 'parent'
class Child(Parent):
def foo(self):
if x:
return x
return super().foo()
import unittest
from unittest.mock import patch
from family import Child
class Tester(unittest.TestCase):
@patch('family.x', False)
def test_calls_super_if_not_x(self, mock_parent_foo):
c = Child()
r =
self.assertEqual(r, mock_parent_foo.return_value)
@patch('family.x', 3)
def test_returns_x_if_x_truthy(self, mock_parent_foo):
c = Child()
r =
self.assertEqual(r, 3)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.