I'm testing with Pytest 3.10 an application mounted on Flask 0.12.2 and Werkzeug 0.14.1. The testing works well only in the end, Pytest shows the summary of the warnings that have been detected throughout the test:
=============================== warnings summary ===============================
tests/test_subdomain.py::TestSubsubdomain::()::test_post[test_input0-201 CREATED]
<PATH_LIB_PROYECTO>/python2.7/site-packages/werkzeug/local.py:347: DeprecationWarning: json is deprecated. Use get_json() instead.
return getattr(self._get_current_object(), name)
# mas warnings de este tipo...
This is the warning that is constantly repeated because when I try to test a POST method, the application returns the following:
# Endpoint cualquiera de la aplicación
# 'entity' es el objeto JSON insertado en la base
# de datos junto con su identificador
return flask.Response(
jsonpickle.encode(entity,unpicklable=False),
CREATED,
mimetype='application/json'
)
The way I have to parse the answer in the tests is the following:
import json
# más imports...
class TestSubdomain(object):
new_data = None
# más tests de la clase...
@pytest.mark.parametrize("test_input, expected", input_test_post_data)
def test_post(self, ste, domain_fxt, test_input, expected):
"""
Post one or more subdomains
"""
rsp = ste['test_client'].post(url, data=generate_subdomain_data(test_input, domain_fxt['domain_id']))
assert rsp.status == expected
TestSubsubdomain.new_data = json.dumps(rsp.data)
I use Python's own json
module to transform the response to JSON since the flask.Response
class does not have a get_json()
method, as%% co_ does. Therefore, I do not understand the reason for the warnings generated by Pytest.
I've seen this Flask issue that seems to have the same problem as me but in my case it's about a response and not a request, therefore it does not help me much.
Is the reason for the warning found in how the application returns the response? Is it perhaps something that happened to the response to JSON in the test?
Thank you very much
References