Design advice for unit test asserters

Gary gfyho at yahoo.com
Wed Apr 27 15:19:01 EDT 2005


First, thanks to both Kent and Edvard for useful comments.  I certainly
need to consider whether it make sense to switch to py.test at this
time; its simplicity is attractive.

In response to Edvards question:

Edvard Majakari wrote:
> "Gary" <gfyho at yahoo.com> writes:
...
> >          self.AssertAllFilesExist(fileList)
...
> >
> >      def test_SomeTest(...):
> >          ...
> >          [ self.AssertFileExists(f) for f in fileList ]
>
> I prefer the latter, because then you'd get error for the missing
file -
> otherwise you'd just know a file didn't exist (but not which, unless
you
> explicitly coded that in, no?)

Yes, my intent is that AssertAllFilesExist(fileList) would be something
like the following, more or less:

    def AssertAllFilesExist(fileList):
        for f in fileList:
            self.assert_(os.path.isfile(f) and not os.path.islink(f),
                         "File %s is missing" % f)

It's the smarts in these that caused me to instantly see applicability
of the Template Pattern - which became quite a distraction to me,
because after doing it, I think it was obviously unnecessary overkill.

Gary




More information about the Python-list mailing list