I have the below:
from datetime import datetime
def get_report_month_key():
month_for_report = datetime.utcnow()
return month_for_report.strftime(\"
If your code is in another file you need to patch where the import happens (lets call your file file1.py):
from file1 import get_report_month_key
import mock
@mock.patch("get_report_month_key.datetime.utcnow")
def test_get_report_month_key(mock_utcnow):
mock_utcnow.return_value = "your value"
assert get_report_month_key() == "your expected value"
Of course, I would wrap it with unittest framework.