Problem When Unit Testing with PMock

Terry Reedy tjreedy at udel.edu
Sat Feb 26 13:44:27 EST 2005


<steven at lczmsoft.com> wrote in message 
news:1109423274.660110.156140 at f14g2000cwb.googlegroups.com...
> Anyone was using pmock for unit testing with python?  I met a problem
> and hope someone to help me.  For short, the pmock seems can not mock a
> iterator object.

Why bother?

def mockit(): raise StopIteration

now pass mockit()

> For example, the tested object is foo, who need to send message to
> another object bar.  So, to test the foo, I need mock a mockBar.  But
> the bar is a iterator, the foo use the bar in this way:
>
>     foo.method(self, bar):
>         for n in bar:
>             do somthing
>              ...

To properly test the method, *also* feed it an iterator that yields a few 
objects of the appropriate type.  Assuming n is to be an int...

def intit(k):
  for i in range(k): yield i

Terry J. Reedy








More information about the Python-list mailing list