allankp / pytest-testrail

pytest plugin for integration with TestRail, for creating testruns and updating results
MIT License
95 stars 125 forks source link

Latest version 1.1.5 has error serializing JSON with Python 3.6 #55

Closed m1yag1 closed 6 years ago

m1yag1 commented 6 years ago

I've testing this with 1.1.4 and the POST request to TestRail to create the test run works as expected. When I upgrade to 1.1.5 the following error occurs:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/_pytest/main.py", line 178, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/_pytest/main.py", line 214, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/_pytest/main.py", line 224, in pytest_collection
INTERNALERROR>     return session.perform_collect()
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/_pytest/main.py", line 429, in perform_collect
INTERNALERROR>     session=self, config=self.config, items=items
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR>     return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR>     firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pluggy/callers.py", line 180, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pytest_testrail/plugin.py", line 175, in pytest_collection_modifyitems
INTERNALERROR>     tr_keys
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pytest_testrail/plugin.py", line 303, in create_test_run
INTERNALERROR>     cert_check=self.cert_check
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/pytest_testrail/testrail_api.py", line 118, in send_post
INTERNALERROR>     timeout=timeout
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/requests/api.py", line 112, in post
INTERNALERROR>     return request('post', url, data=data, json=json, **kwargs)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/requests/api.py", line 58, in request
INTERNALERROR>     return session.request(method=method, url=url, **kwargs)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/requests/sessions.py", line 498, in request
INTERNALERROR>     prep = self.prepare_request(req)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/requests/sessions.py", line 441, in prepare_request
INTERNALERROR>     hooks=merge_hooks(request.hooks, self.hooks),
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/requests/models.py", line 312, in prepare
INTERNALERROR>     self.prepare_body(data, files, json)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/requests/models.py", line 462, in prepare_body
INTERNALERROR>     body = complexjson.dumps(json)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/simplejson/__init__.py", line 382, in dumps
INTERNALERROR>     return _default_encoder.encode(obj)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/simplejson/encoder.py", line 296, in encode
INTERNALERROR>     chunks = self.iterencode(o, _one_shot=True)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/simplejson/encoder.py", line 378, in iterencode
INTERNALERROR>     return _iterencode(o, 0)
INTERNALERROR>   File "/some_project/lib/python3.6/site-packages/simplejson/encoder.py", line 273, in default
INTERNALERROR>     o.__class__.__name__)
INTERNALERROR> TypeError: Object of type map is not JSON serializable
[testrail] Start publishing
[testrail] End publishing`
m1yag1 commented 6 years ago

As indicated to me by a co-worker the error seems to be that the type expected is a list but is actually returning a map. Most likely in this location: https://github.com/allankp/pytest-testrail/blob/2a41191ad4030fa87f36caf8288388525dd333cf/pytest_testrail/plugin.py#L93-L100

Possible fix: return list(map(int, [re.search('(?P<test_id>[0-9]+$)', test_id).groupdict().get('test_id') for test_id in test_ids]))

allankp commented 6 years ago

@m1yag1 This is fixed in 1.1.6