I have 2 files and a test file. For some unknown reason, i could not get this to pass. This tests always fail as it still returns 'hello_world' instead of using the mocked value of 'goodbye_world'.
utils.py
def hello_world():
return "hello_world"
foo.py
from utils import hello_world
class Foo:
def function_a():
return hello_world()
test.py
import foo
from unittest.mock import patch
from unittest import TestCase
class TestStuff(TestCase):
@patch('foo.hello_world')
def test_hello_world(mock_value):
mock_value.return_value = 'goodbye_world'
temp = foo.Foo()
self.assertEqual(temp.function_a(), 'goodbye_world')