1

py中有两个文件

py/
  bubble.py
  unit.py

unit.py是:

import random
import unittest
from py import bubble

def getl():
    l = []
    for i in range(10):
        l.append(random.randint(1,20))
    return l

class TestBubble(unittest.TestCase):
    def setUp(self):
        self.l = getl()

    def test_bubble(self):
        sorted_list = sorted(self.l)
        bubble(self.l)
        self.assertListEqual(self.l, sorted_list)

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

运行此脚本时,我得到了这个:

E
======================================================================
ERROR: test_bubble (__main__.TestBubble)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "unit.py", line 27, in test_bubble
    bubble(self.l)
TypeError: 'module' object is not callable

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (errors=1)

这个脚本有什么问题?

4

1 回答 1

4

这是问题所在:

bubble(self.l)

bubble是一个模块,你尝试像函数一样调用它。例如,您必须调用bubble.func(self.l)where funcis your function。

于 2013-06-03T12:23:04.827 回答