使用 python 进行日期敏感的回归测试
嘿, 我正在帮助为我们的 python Web 应用程序设置回归测试套件。我们的许多测试都是安排式测试,其中当前日期很重要。例如:创建一个从 2 月 1 日开始每周运行一个月的重复事件。
为了测试这一点,我真正想做的是覆盖当前日期,以便我可以及时前后移动以检查状态该应用程序。例如,我可以添加一个仅测试页面,让我设置“当前”日期,该日期传递到 python 后端并用于日期计算。
过去,当我完成此操作时,我从第一天起就将其设计到应用程序架构中。不幸的是,我来得太晚了,并且没有对此的应用程序支持。
所以这是我的问题,有什么方法可以覆盖网络服务调用的当前日期吗?例如,我可以拦截当前日期的呼叫(可能是猴子修补吗?)。我宁愿不必做整个 IOC 的事情,因为这意味着改变数百个方法。 - 戴夫
Hey,
I am helping to set up a regression testing suite for our python web application. Many of our tests are 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以这样做:
不过,在你的类上放置一个辅助方法来获取当前日期,并进行与上面所示相同的猴子修补,这可能是一个更好的主意(不要与第三方库等混在一起) 。
You could do something like this:
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.