Re: Replacing module with a stub for unit testing

2009-06-04 Thread Fuzzyman
On May 23, 2:00 pm, pigmart...@gmail.com wrote: > Hi, > > I'm working on a unit test framework for a module.  The module I'm > testing indirectly calls another module which is expensive to access > --- CDLLs whose functions access a database. > >     test_MyModule --->MyModule--->IntermediateModule

Re: Replacing module with a stub for unit testing

2009-05-29 Thread s4g
Try import sys import ExpensiveModuleStub sys.modules['ExpensiveModule'] = ExpensiveModuleStub sys.modules['ExpensiveModule'].__name__ = 'ExpensiveModule' Should do the trick -- Vyacheslav -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacing module with a stub for unit testing

2009-05-24 Thread Steven D'Aprano
On Sun, 24 May 2009 13:14:30 +0100, A. Cavallo wrote: > how about the old and simple: > > import ExpensiveModuleStub as ExpensiveModule No, that won't do, because for it to have the desired effort, it needs to be inside the IntermediateModule, not the Test_Module. That means that IntermediateM

Re: Replacing module with a stub for unit testing

2009-05-24 Thread A. Cavallo
how about the old and simple: import ExpensiveModuleStub as ExpensiveModule On a different league you could make use of decorator and creating caching objects but that depends entirely on the requirements (how strict your test must be, test data sizes involved and more, much more details). Rega

Re: Replacing module with a stub for unit testing

2009-05-23 Thread Ben Finney
pigmart...@gmail.com writes: > > import ExpensiveModuleStub > sys.modules['ExpensiveModule'] = ExpensiveModuleStub # Doesn't > work > > But, import statements in the IntermediateModule still access the real > ExpensiveModule, not the stub. > > The examples I can find of creating and usi

Re: Replacing module with a stub for unit testing

2009-05-23 Thread Steven D'Aprano
On Sat, 23 May 2009 06:00:15 -0700, pigmartian wrote: > Hi, > > I'm working on a unit test framework for a module. The module I'm > testing indirectly calls another module which is expensive to access --- > CDLLs whose functions access a database. ... > The examples I can find of creating and us