0
嗨,我已經寫了下面基本的Python單元測試代碼:錯誤的單元測試的Python 3.6.1
import unittest
class Phonebooktest(unittest.TestCase):
def test_create_phonebook():
print("welcome to python")
if __name__ == '__main__':
unittest.main()`
我得到一個錯誤:
25
/2
10>>2 2
Traceback (most recent call last):
File "test_phone_book.py", line 1, in <module>
import unittest
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python36\lib\unittest\__init__.py", line 58, in <module>
from .result import TestResult
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python36\lib\unittest\result.py", line 5, in <module>
import traceback
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python36\lib\traceback.py", line 3, in <module>
import collections
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python36\lib\collections\__init__.py", line 26, in <module>
from operator import itemgetter as _itemgetter, eq as _eq
ImportError: cannot import name 'itemgetter'
有人請幫我解決這個錯誤。
「test_phone_book.py」所在的目錄中是否有文件名爲operator.py? –
是的,有operator.py文件。我只是刪除&試過它的工作。我可否知道爲什麼會發生? – jaibalaji
[從腳本導入已安裝的軟件包引發'AttributeError:模塊沒有屬性「或」ImportError:無法導入名稱「]可能的重複](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script -raises-attributeerror-module-has-no-at) –