我試圖在python中運行一些測試。我使用Unittest框架。對象在UnitTest類中沒有屬性「加載」
測試「test_processJson」使用測試Json,dictTestString,然後檢查它是否有一個或多個元素。這是我的腳本「testing.py」
import json
import starter#The code Im trying to test
import unittest
class MyTests(unittest.TestCase):
def test_processJson(json):
dictTestString = '{"city":"Barcelona"}'
jTest = json.loads(dictTestString)
dictProcess = starter.processJson(dictTest)
self.assertEquals(dictProcess["city"], "Barcelona")
if __name__ == '__main__':
unittest.main()
問題是當我運行測試我得到這個錯誤:
Traceback (most recent call last):
File "testing.py", line 16, in test_processJson
jTest = json.loads(dictTestString)
AttributeError: 'MyTests' object has no attribute 'loads'
我是新來的蟒蛇,所以我一直在尋找一個答案,但我看到我沒有做過的任何錯誤。
任何幫助將不勝感激。
謝謝。
謝謝,不能相信我沒有看到! – subharb