[TIP] fresh fixture on module functions
solodex2151 at gmail.com
Mon Mar 5 09:54:22 PST 2007
On 3/5/07, Kumar McMillan <kumar.mcmillan at gmail.com> wrote:
> On 3/4/07, Titus Brown <titus at caltech.edu> wrote:
> > import ObnoxiousModule
> > ObnoxiousModule = module_wrapper(ObnoxiousModule)
> > # modify ObnoxiousModule all you want, and now the global
> > # ObnoxiousModule module won't be touched, e.g.
> > ObnoxiousModule.A = mock_A
> > # ObnoxiousModule.A is now module-local.
> I think the problem with this is that the use case for accessing a
> module that you need to mock *only* in your test itself is limited.
> Most of the time the module attribute I need to mock has to be global
> for it to do what I want. Thus, enter the fairly lame idiom of:
> _saved_A = ObnoxiousModule.A
> ObnoxiousModule.A - mocked_A
> ObnoxiousModule.A = _saved_A
> I bet there are some mock libraries out there that simplify this
> approach but I use mocks so rarely that I haven't bothered to dig in.
I was thinking about possibly doing it this way. As far as I know the
mock libraries only deal with instantiated objects.
You could take the automatic approach and create a module that defines
saveModule and restoreModule functionality.
Titus, I think that this approach will be easier to implement than the
getattr or copy functionality we talked about. I will see about doing
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
More information about the testing-in-python