I want to mock datetime.utcnow().isoformat()
for unittesting of python3 flask application.
I already checked the StackOverflow post of Python: How do I mock datetime.utcnow()?, but couldn't adapt it to utcnow().isoformat.()
.
I tried to edit following code, but it didn't work.
import pytest
import unittest
from unittest import mock
def fake_datetime(*args, **kwargs):
class FakeTime:
@classmethod
def utcnow(self):
return "2020-03-17T10:02:01.285418"
return Faketime
@mock.patch('app.utils.datetime', side_effect=fake_datetime)
class FlaskRoutesTest(unittest.TestCase):
def setUp(self):
self.app = app.create_app().test_client()
def test_app_route_recovered(self, mock_datetime):
print(mock_get.utcnow().isoformat())