第一次尝试使用unittest
模块,但似乎无法导入模块?我只是在尝试使用unittest
来测试我创建的一个简单函数。
代码&抛出错误:
import unittest
from name_function import get_formatted_name
class NameTestCase(unittest.TestCase):
#tests name_function.py
def test_first_last(self):
formatted_name = get_formatted_name('first','last')
self.assertEqual(formatted_name, 'First Last')
unittest.main()
错误:
Traceback (most recent call last):
File "H:\Documents\Scripts_H\CrashCourse\test_name_function.py", line 1, in <module>
import unittest
File "C:\Users\name\AppData\Local\Programs\Python\Python35-32\lib\unittest\__init__.py", line 58, in <module>
from .result import TestResult
File "C:\Users\name\AppData\Local\Programs\Python\Python35-32\lib\unittest\result.py", line 5, in <module>
import traceback
File "C:\Users\name\AppData\Local\Programs\Python\Python35-32\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\name\AppData\Local\Programs\Python\Python35-32\lib\linecache.py", line 8, in <module>
import functools
File "C:\Users\name\AppData\Local\Programs\Python\Python35-32\lib\functools.py", line 21, in <module>
from collections import namedtuple
ImportError: cannot import name 'namedtuple'
我在其他帖子中读到collections
模块存在问题,但不确定这是否是类似的问题。就Python文档所述,unittest
应该是一个正常的模块,对吧?任何想法可能是什么问题?