diff --git a/sanic/testing.py b/sanic/testing.py index 4fde428c..1cad6a7b 100644 --- a/sanic/testing.py +++ b/sanic/testing.py @@ -22,7 +22,10 @@ class SanicTestClient: cookies=cookies, connector=conn) as session: async with getattr( session, method.lower())(url, *args, **kwargs) as response: - response.text = await response.text() + try: + response.text = await response.text() + except UnicodeDecodeError as e: + response.text = None response.body = await response.read() return response diff --git a/tests/static/python.png b/tests/static/python.png new file mode 100644 index 00000000..52fda109 Binary files /dev/null and b/tests/static/python.png differ diff --git a/tests/test_static.py b/tests/test_static.py index 783a56c7..091d63a4 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -25,7 +25,7 @@ def get_file_content(static_file_directory, file_name): return file.read() -@pytest.mark.parametrize('file_name', ['test.file', 'decode me.txt']) +@pytest.mark.parametrize('file_name', ['test.file', 'decode me.txt', 'python.png']) def test_static_file(static_file_directory, file_name): app = Sanic('test_static') app.static(