python - object has no attribute 'loads' in UnitTest class -


im trying run tests in python. im using unittest framework.

the test "test_processjson" uses test json, dictteststring, , checks if has 1 or more elements. script "testing.py"

import json import starter#the code im trying 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() 

the problem comes when run test error:

traceback (most recent call last):

file "testing.py", line 16, in test_processjson

jtest = json.loads(dictteststring)

attributeerror: 'mytests' object has no attribute 'loads'

i'm new python, i've been looking answer of mistakes i've seen im not doing.

any appreciated.

thanks.

your function's argument named json, shadow's global json module. since first argument of method, bound current mytest instance, , since unittest test methods expect current instance argument , don't have need json argument here, have rename self (which convention first argument of instance methods) , problem solved.

nb : there couple other typos / issues code leave find , solve them - that's part of fun isn't ?


Comments

Popular posts from this blog

cookies - Yii2 Advanced - Share session between frontend and mainsite (duplicate of frontend for www) -

angular - password and confirm password field validation angular2 reactive forms -

php - Permission denied. Laravel linux server -