Skip to content
Advertisement

How to unittest a datetime function

file.py

JavaScript

test.py

JavaScript

I get an Error: TypeError: ‘>’ not supported between instances of ‘MagicMock’ and ‘int’

Is there anyway to test this function?

Probably the problem is with this part of the last line: (utc_date - namespace_created_date).days

Advertisement

Answer

I could reproduce and fix.

Here is a working unittest file (assuming file.py is accessible):

JavaScript

If I use date_now.datetime.utcnow.date.return_value = datetime.datetime(2022,1,1) I have the same error as you have, but removing .date is enough to have the test to pass.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement