debugging JSON encoder issues

19 views
Skip to first unread message

Jonathan Vanasco

unread,
Mar 15, 2021, 5:57:11 PM3/15/21
to pylons-discuss
I've run into this same problem a few times in unittest. I'm hoping someone else has a better solution.

1. The test harness uses webtest.TestApp to mount the Pyramid application 
2. A route has a payload with an object that can not be rendered into json
3. The traceback looks like the item below.

The problem is call stack doesn't have any information about my app-code that generated the render/exception.  I can match it to a route, via the line in the test harness, but that's it.  Because I have no idea where the return/response happened in the route logic, I often spend a lot of time with pdb breakpoints in the route trying to figure out what line caused it - as the return value could have been generated in multiple spots.

Has anyone figured out a standard way of dealing with this type of situation?

----

Traceback (most recent call last):

  File "/Users/jvanasco/webserver/os-projects-mine/project/tests/test_pyramid_app.py", line 6402, in test_post_required_json

    res = self.testapp.get(

    ....

    lots of webob/pyramid/etc items in the stack

    ... 

  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pyramid/renderers.py", line 298, in default

    raise TypeError('%r is not JSON serializable' % (obj,))

TypeError: <project.model.objects.Object object at 0x10c6a34f0> is not JSON serializable


Reply all
Reply to author
Forward
0 new messages