Created
July 8, 2020 15:04
-
-
Save gibizer/b6f22986381be3437c8e9fc369c462e0 to your computer and use it in GitHub Desktop.
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
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