'Pytest mock patch function not called
I am sure that a function is called (because of a print statement on it).
My test target is the function handle_action.
__init__.py
from .dummy import HANDLE_NOTHING, handle_nothing
handlers = {
HANDLE_NOTHING: handle_nothing,
}
def handle_action(action, user, room, content, data):
func = handlers.get(action)
if func:
func(user, room, content, data)
Unit test
import mock
from handlers import HANDLE_NOTHING, handle_action
def test_handle_dummy_action():
action = HANDLE_NOTHING
user = "uid"
room = "room"
content = "test"
data = {}
with mock.patch("handlers.dummy.handle_nothing") as f:
handle_action(action, user, room, content, data)
f.assert_called_with()
When I run I get:
E AssertionError: expected call not found.
E Expected: handle_nothing()
E Actual: not called.
If I change from handlers.dummy.handle_nothing to handlers.handle_nothing I receive the same error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
