Maciek Fijalkowski wrote:
> Michael Hipp wrote:
>> What's the best technique for this?
>>
>> My current project uses lots of timestamps ( i.e now(), today() ) but 
>> this causes lots of things to return different results with every run. 
>> So for the cases where the module under test needs to return results 
>> that are binary repeatable with every run, I want to centralize all my 
>> calls to the above functions in one place and have them return a 
>> predetermined value when under test.
>>
>> So how best to communicate to a module that it is under test and a few 
>> certain things need to modify their behavior slightly?
>>
>> Just looking for "best practices" here.
> I would go for
> 
> import foo
> 
> def setup_module(mod):
>   try:
>       old_now = foo.now
>       foo.now = a_day
>       ....
>   finally:
>       foo.now = old_now

Thanks!

Michael
_______________________________________________
py-dev mailing list
py-dev@codespeak.net
http://codespeak.net/mailman/listinfo/py-dev

Reply via email to