After looking at the new stuff available in unit tests:
http://docs.python.org/library/unittest.html
I am really sold! At a mere glance I can already see two things that would be supremely useful in cleaning up my tests which is:
doCleanups
and
assert*Equal
Especially the assertTupleEqual and assertListEqual is really really nice where in the difference of the two sets are compared and the diff included in the failed message. We are using Ubuntu on all of our tests machines so I really hope that the stock Python that comes with the next version of Ubuntu is the 2.7.x branch. The assertAlmostEqual seems a bit dodgy to me but then again I still haven't really gone in depth with the docs yet.
What would be a nice addition for me would be 'assertTextFileEqual' or something to that end. This would be a great shortcut for me as I do a lot of text file reading and asserting in my tests.
All in all kudos to the changes made in the unit test module of Python and I like the direction that it's heading.
Sunday, October 9, 2011
Subscribe to:
Post Comments (Atom)
11 comments:
Uhm, Natty has 2.7.1+ already. No need to wait. :)
What hynek said. Also, maverick had 2.7 available, which means most modules work with it, but not everything so it isn't the default "python".
python2.7 package page
unittest2 is a backport for python 2.4 to 2.6
and to easily switch between the two, you could do something like
try:
import unittest2 as unittest
catch ImportError:
import unittest
assertAlmostEqual has been in unittest for years, it just gets more useful in 2.7 (and in unittest2).
you can try this library that extends unittest.TestCase:
logilab.common.testlib.TestCase.assertFileEquals
need a:
apt-get install python-logilab-common
Writing your own assert methods is very easy, and you have the difflib for comparing text files.
vfaronov that is a superb suggestion! Thanks!
alain ... interesting! Did not know that!
http://lists.logilab.org/pipermail/python-projects/2010-December/002783.html Hmmm ... they don't really suggest we use it though ...
Maybe I'm missing something but how about doing it like this?
http://stackoverflow.com/questions/5233536/python-2-7-on-ubuntu
Or does it have to be 'official'?
Chai absolutely nothing wrong with that just that I don't really have the bandwidth to go tinkering with the python versions on those boxes.
Post a Comment