unittest

Z

Zunbeltz Izaola

Hi,

I am using unittest for the first time. I have read chapter 7 of dive into
pyhton (Unit Test). I have the following code

from spacegroup import *
import pygroups.misc.matrix as matrix
import unittest

class KnowValues(unittest.TestCase):

KnownRotationMatrices = [
((Rotational3Part([[-1,0,0],[0,1,0],[0,0,-1]])),
(1, -1, 2, matrix.vector([0,1,0])))
]

def TestRotationalPartdeterminant(self):
""" RotationalPart. determinant with known values."""
for i in self.KnownRotationMatrices:
det = i[0].determinant()
self.assertEqual(det,i[1][0])


if __name__ == "__main__":
unittest.main()

but when i run this scrip i get the following output


----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Why the test didn't run? any idea?

TIA

Zunbeltz
 
S

Skip Montanaro

Zunbeltz> class KnowValues(unittest.TestCase):

Zunbeltz> KnownRotationMatrices = [
Zunbeltz> ((Rotational3Part([[-1,0,0],[0,1,0],[0,0,-1]])),
Zunbeltz> (1, -1, 2, matrix.vector([0,1,0])))
Zunbeltz> ]

Zunbeltz> def TestRotationalPartdeterminant(self):
Zunbeltz> """ RotationalPart. determinant with known values."""
Zunbeltz> for i in self.KnownRotationMatrices:
Zunbeltz> det = i[0].determinant()
Zunbeltz> self.assertEqual(det,i[1][0])


Zunbeltz> if __name__ == "__main__":
Zunbeltz> unittest.main()

Zunbeltz> but when i run this scrip i get the following output

...

Try renaming your test case method "test_rotational_partdeterminant".

Skip
 
D

David Goodger

Zunbeltz said:
> Tnaks, why is this so?

From the fine manual
(http://www.python.org/doc/current/lib/minimal-example.html):

A testcase is created by subclassing unittest.TestCase. The three
individual tests are defined with methods whose names start with
the letters "test". This naming convention informs the test runner
about which methods represent tests.

The convention is necessary because you might want methods that are
*not* tests.

-- David Goodger
 
J

Jeremy Fincher

Change your method name to begin with "test" instead of "Test" and it should work.

Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top