视窗 XP Python 2.7
我正在关注 Python 入门书中的代码,并且在名为 testing 的文件夹中有两个文件。我试图让它失败,但它甚至不会运行测试。第一个文件 my_math.py 只是一个虚拟产品函数
def product(x, y):
pass
第二个是测试test_my_math.py
import unittest, my_math
class ProductTestCase(unittest.TestCase):
def testIntegers(self):
for x in xrange(-10, 10):
for y in xrange(-10, 10):
p = my_math.product(x, y)
self.failUnless(p == x*y, 'Integer multiplication failed')
def testFloats(self):
for x in xrange(-10, 10):
for y in xrange(-10, 10):
x = x/10.0
y = y/10.0
p = my_math.product(x, y)
self.failUnless(p == x*y, 'Float multiplicaton failed')
if __name__ == '__main__': unittest.main()
当我在命令行中运行测试时
C:\Python27\Example_Programs\testing>python test_my_math.py
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
C:\Python27\Example_Programs\testing>