开发者

Date sensitive regression testing using python

Hey, I am helping to set up a regression testing suite for our python web application. Many of our tests ar开发者_JS百科e scheduling style tests where the current date is important. For example: create a recurring event that runs every week for a month starting on Feb 1.

In order to test this, what I really want to do is override the current date so I can move back and forward in time to check the state of the app. For example, I may add an test-only page that lets me set the 'current' date which gets passed to the python back end and is used for date calculations.

In the past when I have done this, I engineered it into the application architecture from day 1. Unfortunately, I am coming in late to this project and there is no application support for this.

So here's my question, is there any way I can override the current date on a web service call? For example, can I intercept calls for the current date (monkey patching possibly?). I would rather not have to do a whole IOC thing as it would mean changing hundreds of methods. - dave


You could do something like this:

from datetime import datetime
orig_datetime_now = datetime.now

datetime.now = lambda: datetime(2010, 2, 1)

# tests here

datetime.now = orig_datetime_now

Though, it's probably a better idea (as not to screw with third party libraries, etc.) to put a helper method on your class to get the current date, and do the same monkey patching as show above.


Answering my own question:

Our current plan is to test on virtual machines and change the date/time on the VMs. This is a more complete solution as it gets the database and worker threads all at once.

I'll post an update with some real world experience when we come to actual do it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜