Design advice for unit test asserters
Edvard Majakari
edvard+news at majakari.net
Fri Apr 22 01:43:36 EDT 2005
"Gary" <gfyho at yahoo.com> writes:
[ py.test ad follows :) ]
> def test_SomeTest(...):
> ...
> self.AssertAllFilesExist(fileList)
>
> or
>
> 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?)
with py.test you could just write:
def file_exists(fname):
assert os.path.isfile(fname)
def test_file_exists():
for f in fileList:
yield file_exists, f
that way you'd generate a separate test for each file in fileList, and easily
see which file would fail the test. :)
no comment for the rest of your posts though - I'm still learning how to
create good unit tests myself (and I also see you're using standard unit test
modules - I'm already seduced by the no-API py.test library...)
--
# Edvard Majakari Software Engineer
# PGP PUBLIC KEY available Soli Deo Gloria!
$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
More information about the Python-list
mailing list