unittest: Proposal to add failUnlessNear

Michael Hudson mwh at python.net
Tue Jul 20 14:06:57 EDT 2004


Tim Peters <tim.peters at gmail.com> writes:

> [John Roth]
> > I think this is overkill. I find myself using a raw assert much of the time
> > rather than unittest's specific test methods; it works just as well and I
> > don't have to remember the blasted syntax!
> 
> It doesn't work as well, because assert stmts "vanish" when running
> tests with -O.  Luckily,
> 
>     self.assert_(expression)
> 
> works fine in a unittest, with or without -O.
> 
>     self.assertEqual(e1, e2)
> 
> is usually a lot better than
> 
>     self.assert_(e1 == e2)
> 
> too, because the former displays the unequal values when it fails.

Have you seen Holger Krekel's utest?

$ cat test.py
def test_something():
    assert "abc"[::-1] == "cab"
$ python2.3 ./std/bin/utest test.py 
inserting /home/mwh/src/pypy
_______________________________________________________________________________
______________________________  TESTS STARTING  ______________________________
_______________________________________________________________________________
F

_______________________________________________________________________________
________________________________ Test Failure ________________________________

>>> test_something
>>> '/home/mwh/src/pypy/test.py', line 2

def test_something():
>   assert "abc"[::-1] == "cab"

-------------------------------------------------------------------------------
assert 'cba' == 'cab'
============================== 1 TESTS FINISHED ==============================
0.06 seconds (0 passed, 1 failed, 0 skipped)

Doesn't seem to be the easiest to install package I've ever used,
mind...

Cheers,
mwh

-- 
8. A programming language is low level when its programs require
   attention to the irrelevant.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html



More information about the Python-list mailing list