[TIP] Testing becomes testing implementation rather than behavioral

Kate Katee wjwxinst at gmail.com
Sun Feb 10 14:55:30 PST 2013


Hi,

Suppose I have this piece of code:

def some_func(parm1, parm2, ....):
    if os.path.exists(param1):
          // do a bunch of os operation using shutil, os, and some other
custom libraries (hashing, etc)
    return result

So if I want to write a unittest, I'd mock out os.path.exists and just
about everything in this function! That's testing against implementation
rather than the behavioral of the function (does the output matches the
expected).
In some cases, I can put everything complex into individual functiosn

def some_func(parm1, parm2....):
    func1(..)
    func2(...)
    return result

But I still have to test func1 and func2. So at the end of the day, I still
have to mock many things out.

How would do test it? I know I can setup some fixture data like real files,
but that's slow. I might as well just write an integration test and forget
about my unittest, but that could run a long time.

Thanks a lot!

Kate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20130210/59ea96b6/attachment.htm>


More information about the testing-in-python mailing list