Skip to content

Instantly share code, notes, and snippets.

@whaley
Created September 13, 2019 19:13
Show Gist options
  • Save whaley/863036250710ccae845ac5f92b00fa36 to your computer and use it in GitHub Desktop.
Save whaley/863036250710ccae845ac5f92b00fa36 to your computer and use it in GitHub Desktop.
class Foo:
def a(self):
...
def b(self):
... #this doesn't return anything, but has side effects that are important, but expensive to poll for
class UsesFoo():
def __init__(self,foo):
self.foo = foo
def run(self):
self.foo.a()
if some_condition:
self.foo.b()
#in test code
from testing.mock import patch
def test_b_not_called():
with patch.object(Foo,"b"):
foo = Foo()
u = UsesFoo(foo)
u.run()
foo.b.assert_not_called()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment