From e86dbbf7ab114688bb48fefd41238657f200aff4 Mon Sep 17 00:00:00 2001 From: Andrew Zhou <30874884+0az@users.noreply.github.com> Date: Mon, 8 Oct 2018 17:06:48 -0700 Subject: [PATCH] Add test for default logger --- aiohttp/web.py | 2 +- tests/test_run_app.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/aiohttp/web.py b/aiohttp/web.py index ca8e8cb4de8..ba25d153cf0 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -53,7 +53,7 @@ def run_app(app, *, host=None, port=None, path=None, sock=None, app = loop.run_until_complete(app) # Configure if and only if in debugging mode and using the default logger - if app.debug and access_log is access_logger: + if app.debug and access_log.name == 'aiohttp.access': if access_log.level == logging.NOTSET: access_log.setLevel(logging.DEBUG) if not access_log.hasHandlers(): diff --git a/tests/test_run_app.py b/tests/test_run_app.py index 1287741ec43..c31412a143d 100644 --- a/tests/test_run_app.py +++ b/tests/test_run_app.py @@ -1,5 +1,6 @@ import asyncio import contextlib +import logging import os import platform import signal @@ -539,3 +540,27 @@ async def make_app(): reuse_port=None) startup_handler.assert_called_once_with(mock.ANY) cleanup_handler.assert_called_once_with(mock.ANY) + + +def test_run_app_default_logger(monkeypatch, patched_loop): + logger = web.access_logger + attrs = { + 'hasHandlers.return_value': False, + 'level': logging.NOTSET, + 'name': 'aiohttp.access', + } + mock_logger = mock.create_autospec(logger, name='mock_access_logger') + mock_logger.configure_mock(**attrs) + # with monkeypatch.context() as m: + # m.setattr(web, + # 'run_app', + # functools.partial(web.run_app, + # access_log=mock_logger)) + app = web.Application(debug=True) + web.run_app(app, + print=stopper(patched_loop), + access_log=mock_logger) + mock_logger.setLevel.assert_any_call(logging.DEBUG) + mock_logger.hasHandlers.assert_called_with() + assert isinstance(mock_logger.addHandler.call_args[0][0], + logging.StreamHandler)