This is a reference on how to mock out the datetime.now() call in python using mox. Since datetime is a built-in it makes things a little more tricky.
def test_datetime(self):
now = datetime.datetime.now() # Store it for later use
m.StubOutWithMock(datetime, 'datetime')
datetime.datetime.now().AndReturn(now)
m.ReplayAll()
datetime.datetime.now()
m.VerifyAll()
m.UnsetStubs()
First we will store the current datetime, this has to be done before mocking takes place. Next we use StubOutWitMock to mock out the datetime class, we then record the call to now and have it return our stored now. If you have any question leave them in the comments.
Links:
