[py-dev] How best to notify modules?
Maciek Fijalkowski
fijal at genesilico.pl
Sat Feb 24 18:35:52 CET 2007
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.
>
> Thanks,
> Michael
> _______________________________________________
> py-dev mailing list
> py-dev at codespeak.net
> http://codespeak.net/mailman/listinfo/py-dev
>
I would go for
import foo
def setup_module(mod):
try:
old_now = foo.now
foo.now = a_day
....
finally:
foo.now = old_now
More information about the py-dev
mailing list