I'm writing a test for a specific function that I wrote the uses datetime.utcnow()
, which is necessary as it functions in real-time. The test is shaped like this:
1.Test:
*Important_Date, in datetime format*
Function which uses Important_Date
*assertfunction*
2.Function which uses Important_Date
if Condition:
return Important_Date < (datetime.utcnow() - timedelta(days=7))
Now, the problem is, whenever Important_Date
is less than 7
days from datetime.utcnow()
, the test case passes. If not, it fails.
Now, the requirement is that Important_Date
should be set to something like one/two/three days before the date which I get from datetime.utcnow()
. I'm confused as to how this is to be done.
I've tried datetime.utcnow() - 1
, which is not working.
Is there a way to do this? Any help is appreciated.
I'm using Python 3, on PyCharm, running on Windows 10.