I'm trying to use unittest.mock to mock an import in a module under test.
What I'm seeing is that although my module calls sleep 5 times the mock object I'm interacting with in the test function isn't what I'm expecting.
I'm assuming I'm not doing something correctly. I did read the docs, but I'm sure I'm not doing this correctly.
"""example.py"""
import time
def mycode():
time.sleep(10)
time.sleep(10)
time.sleep(10)
time.sleep(10)
time.sleep(10)
"""test_example.py"""
import example
from unittest.mock import patch
@patch("example.time.sleep")
def test_example(mock_time):
example.mycode()
assert mock_time.call_count == 5