test_logging.py
This file
Path
tests/test_logging.py
105 lines · 2.6 KiB · Python
Last changed by
Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
History of this fileTake it
The walk stopped after 200 commits: lines older than c74f469 point at it.
Merge pull request #2624 from pallets/metadataDavid Lordbefore adoption4309c7c
lines 1–9why, one step back1# -*- coding: utf-8 -*-2"""3tests.test_logging4~~~~~~~~~~~~~~~~~~~56:copyright: © 2010 by the Pallets team.7:license: BSD, see LICENSE for more details.8"""9Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 10–15why, one step back10import logging11import sys1213import pytest1415from flask._compat import StringIOMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 16why, one step back16from flask.logging import default_handler, has_level_handler, wsgi_errors_streamMerge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 17–19why, one step back171819@pytest.fixture(autouse=True)Merge pull request #2554 from camilojimenez/2550-some-tests-failDavid Lordbefore adoption27a7171
line 20why, one step back20def reset_logging(pytestconfig):Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 21why, one step back21 root_handlers = logging.root.handlers[:]Merge pull request #2554 from camilojimenez/2550-some-tests-failDavid Lordbefore adoption27a7171
line 22why, one step back22 logging.root.handlers = []Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 23–24why, one step back23 root_level = logging.root.level24Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 25why, one step back25 logger = logging.getLogger("flask.app")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 26–28why, one step back26 logger.handlers = []27 logger.setLevel(logging.NOTSET)28Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 29why, one step back29 logging_plugin = pytestconfig.pluginmanager.unregister(name="logging-plugin")Merge pull request #2554 from camilojimenez/2550-some-tests-failDavid Lordbefore adoption27a7171
line 30why, one step back30Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 31–37why, one step back31 yield3233 logging.root.handlers[:] = root_handlers34 logging.root.setLevel(root_level)3536 logger.handlers = []37 logger.setLevel(logging.NOTSET)Merge pull request #2554 from camilojimenez/2550-some-tests-failDavid Lordbefore adoption27a7171
lines 38–39why, one step back3839 if logging_plugin:Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 40why, one step back40 pytestconfig.pluginmanager.register(logging_plugin, "logging-plugin")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 41–43why, one step back414243def test_logger(app):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 44why, one step back44 assert app.logger.name == "flask.app"Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 45–61why, one step back45 assert app.logger.level == logging.NOTSET46 assert app.logger.handlers == [default_handler]474849def test_logger_debug(app):50 app.debug = True51 assert app.logger.level == logging.DEBUG52 assert app.logger.handlers == [default_handler]535455def test_existing_handler(app):56 logging.root.addHandler(logging.StreamHandler())57 assert app.logger.level == logging.NOTSET58 assert not app.logger.handlers596061def test_wsgi_errors_stream(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 62why, one step back62 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 63why, one step back63 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 64–65why, one step back64 app.logger.error("test")65 return ""Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 66–67why, one step back6667 stream = StringIO()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 68–69why, one step back68 client.get("/", errors_stream=stream)69 assert "ERROR in test_logging: test" in stream.getvalue()Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 70–77why, one step back7071 assert wsgi_errors_stream._get_current_object() is sys.stderr7273 with app.test_request_context(errors_stream=stream):74 assert wsgi_errors_stream._get_current_object() is stream757677def test_has_level_handler():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 78why, one step back78 logger = logging.getLogger("flask.app")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 79–93why, one step back79 assert not has_level_handler(logger)8081 handler = logging.StreamHandler()82 logging.root.addHandler(handler)83 assert has_level_handler(logger)8485 logger.propagate = False86 assert not has_level_handler(logger)87 logger.propagate = True8889 handler.setLevel(logging.ERROR)90 assert not has_level_handler(logger)919293def test_log_view_exception(app, client):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 94why, one step back94 @app.route("/")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
line 95why, one step back95 def index():Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 96why, one step back96 raise Exception("test")Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 97–99why, one step back9798 app.testing = False99 stream = StringIO()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 100why, one step back100 rv = client.get("/", errors_stream=stream)Merge pull request #2436 from davidism/loggingDavid Lordbefore adoptionc74f469
lines 101–103why, one step back101 assert rv.status_code == 500102 assert rv.data103 err = stream.getvalue()Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 104–105why, one step back104 assert "Exception on / [GET]" in err105 assert "Exception: test" in err