Hiding the trace may give you a more understandable test result.
Try to verify that the /runningweb API endpoint returns a JSON response {"running": true}:
import pytest
import json
def test_running(client):
action_response = client.get('/running')
assert parse_as_json(action_response) == {'running': True}
def parse_as_json(response):
__tracebackhide__ = True
try:
return json.loads(response.data)
except json.decoder.JSONDecodeError:
pass
pytest.fail(f'Expected JSON, but got {response.data}')
If the test fails (because the JSON is distorted), then the error will be displayed as
__________________________ test_running _________________________
client = <FlaskClient <Flask 'webapi'>>
def test_running(client):
action_res = client.get('/running')
> assert parse_as_json(action_res) == {'running': True}
E Failed: Expected JSON, but got b'ok'
webapi_test.py:22: Failed
=============== 1 failed, 1 passed in 0.15 seconds ===============
whereas without a __tracebackhide__ = Trueconclusion there will be
__________________________ test_running _________________________
client = <FlaskClient <Flask 'webapi'>>
def test_running(client):
action_res = client.get('/running')
> assert parse_as_json(action_res) == {'running': True}
webapi_test.py:22:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
client = <FlaskClient <Flask 'webapi'>>
def test_running(client):
action_res = client.get('/running')
> assert parse_as_json(action_res) == {'running': True}
E Failed: Expected JSON, but got b'ok'
webapi_test.py:22: Failed
=============== 1 failed, 1 passed in 0.17 seconds ===============
source
share