Skip to content

Instantly share code, notes, and snippets.

@gibizer
Created July 8, 2020 15:04
Show Gist options
  • Save gibizer/b6f22986381be3437c8e9fc369c462e0 to your computer and use it in GitHub Desktop.
Save gibizer/b6f22986381be3437c8e9fc369c462e0 to your computer and use it in GitHub Desktop.
import unittest
from unittest import mock
class System:
def __init__(self):
self.counter1 = 0
self.counter2 = 0
def foo(self):
self.counter1 += 1
def bar(self):
self.counter2 += 1
class SystemTest(unittest.TestCase):
def setUp(self):
super().setUp()
patcher = mock.patch.object(System, 'foo')
patcher.start()
def test_bar(self):
system = System()
system.bar()
self.assertEqual(1, system.counter2)
class SystemTest2(unittest.TestCase):
def setUp(self):
super().setUp()
patcher = mock.patch.object(System, 'bar')
patcher.start()
def test_foo(self):
system = System()
system.foo()
self.assertEqual(1, system.counter1)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment