I have a mock that works fine as expected.
from mock import patch
def second(arg):
return 3
def first():
return second('arg')
@patch('test.second')
def test_test(second_mock):
second_mock.return_value = 47 # We decide this
call_it = first()
second_mock.assert_called_once()
second_mock.assert_called_with('arg')
assert call_it == 47
But not if i move me second() method to another file...
from mock import patch
from test_help import second
def first():
return second('arg')
@patch('test_help.second')
def test_test(second_mock):
second_mock.return_value = 47 # We decide this
call_it = first()
second_mock.assert_called_once()
second_mock.assert_called_with('arg')
assert call_it == 47
I get the same error: AssertionError: Expected 'second' to have been called once. Called 0 times.
What am I missing here?
I have tried a few different ways of formatting, but none seem to work. Is this even the best practice/package in this case for unit testing?