From 8a85651e075f8b9bbf19540ae2e5743b904775f9 Mon Sep 17 00:00:00 2001 From: Antoine Pietri Date: Tue, 12 Sep 2017 10:02:14 +0200 Subject: [PATCH] run_app: make print=None disable printing (#2260) --- CONTRIBUTORS.txt | 1 + aiohttp/web.py | 5 +++-- changes/2260.feature | 1 + docs/web_reference.rst | 3 ++- tests/test_run_app.py | 2 +- 5 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 changes/2260.feature diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 7543c7dfd22..beef313fab7 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -29,6 +29,7 @@ Andrew Leech Andrew Lytvyn Andrew Svetlov Andrii Soldatenko +Antoine Pietri Anton Kasyanov Arthur Darcet Ben Bader diff --git a/aiohttp/web.py b/aiohttp/web.py index 6caee4ce10d..64d56167d42 100644 --- a/aiohttp/web.py +++ b/aiohttp/web.py @@ -447,8 +447,9 @@ def run_app(app, *, host=None, port=None, path=None, sock=None, pass try: - print("======== Running on {} ========\n" - "(Press CTRL+C to quit)".format(', '.join(uris))) + if print: + print("======== Running on {} ========\n" + "(Press CTRL+C to quit)".format(', '.join(uris))) loop.run_forever() except (GracefulExit, KeyboardInterrupt): # pragma: no cover pass diff --git a/changes/2260.feature b/changes/2260.feature new file mode 100644 index 00000000000..f78f339226a --- /dev/null +++ b/changes/2260.feature @@ -0,0 +1 @@ +run_app: Make print=None disable printing diff --git a/docs/web_reference.rst b/docs/web_reference.rst index a98929b7199..e7cb203c711 100644 --- a/docs/web_reference.rst +++ b/docs/web_reference.rst @@ -2400,7 +2400,8 @@ Utilities ``None`` for HTTP connection. :param print: a callable compatible with :func:`print`. May be used - to override STDOUT output or suppress it. + to override STDOUT output or suppress it. Passing `None` + disables output. :param int backlog: the number of unaccepted connections that the system will allow before refusing new diff --git a/tests/test_run_app.py b/tests/test_run_app.py index 63fbe10d6bf..89629de36a1 100644 --- a/tests/test_run_app.py +++ b/tests/test_run_app.py @@ -214,7 +214,7 @@ def test_run_app_mixed_bindings(mocker, run_app_kwargs, expected_server_calls, loop = mocker.MagicMock() mocker.patch('asyncio.gather') - web.run_app(app, loop=loop, print=lambda *args: None, **run_app_kwargs) + web.run_app(app, loop=loop, print=None, **run_app_kwargs) assert loop.create_unix_server.mock_calls == expected_unix_server_calls assert loop.create_server.mock_calls == expected_server_calls