我试图在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