Here is my project structure
|-- project
|-- util.py
|-- main.py
|-- tests
|-- test_main.py
In the main.py
file I reference the function in util.py
from util import rename
def use_rename():
after_rename = rename("name")
return after_rename
And this is how I implement the rename
function in util.py
def rename(name: str) -> str:
return name
Finally I test it in the test_main.py
file
import sys
import os
from unittest.mock import patch
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from main import use_rename
@patch("util.rename")
def test_use_rename(mock_rename):
mock_rename.return_value = "name2"
assert use_rename() == "name"
As you can see I try to mock the return result of the rename
function and assume the test should fail, but it always succeeds. Is there anything wrong with my code?