Skip to content

Instantly share code, notes, and snippets.

@bonprosoft
Last active September 20, 2019 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bonprosoft/0de79f50852091f0022f75e10d29bc13 to your computer and use it in GitHub Desktop.
Save bonprosoft/0de79f50852091f0022f75e10d29bc13 to your computer and use it in GitHub Desktop.
mock.patch 検証2
import hoge
from hoge import A
def print_value():
instance = A()
print(instance.value)
def print_value2():
instance = hoge.A()
print(instance.value)
class A:
value = 10
from unittest import mock
import fuga
class B:
value = 100
def test():
with mock.patch('hoge.A', B):
fuga.print_value()
fuga.print_value2()
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment