简体   繁体   中英

TypeError: 'module' object is not callable when running unittest

There are two files in py

py/
  bubble.py
  unit.py

unit.py is:

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()

When running this script i got this:

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)

What's the problem with this script?

This the line with the problem:

bubble(self.l)

bubble is a module and you try to call it like a function. For example, you must call bubble.func(self.l) where func is your function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM