test_logging.py — flask Source File
Architecture documentation for test_logging.py, a python file in the flask codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 15728ce1_f012_a726_8605_c127320eeec1["test_logging.py"] 9519a04a_d57b_a8a9_24e1_5d65cbdb5708["logging"] 15728ce1_f012_a726_8605_c127320eeec1 --> 9519a04a_d57b_a8a9_24e1_5d65cbdb5708 8e9cc1cb_fabe_237c_ff24_85400e094882["sys"] 15728ce1_f012_a726_8605_c127320eeec1 --> 8e9cc1cb_fabe_237c_ff24_85400e094882 ae09b50b_b5d6_a85f_ee35_4bca99dcf5dd["io"] 15728ce1_f012_a726_8605_c127320eeec1 --> ae09b50b_b5d6_a85f_ee35_4bca99dcf5dd da94d511_b8b8_a450_f67f_fc28ea9b648a["pytest"] 15728ce1_f012_a726_8605_c127320eeec1 --> da94d511_b8b8_a450_f67f_fc28ea9b648a 7f7c40d5_7ad0_e5f2_607a_92f730a59c26["flask.logging"] 15728ce1_f012_a726_8605_c127320eeec1 --> 7f7c40d5_7ad0_e5f2_607a_92f730a59c26 style 15728ce1_f012_a726_8605_c127320eeec1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import logging
import sys
from io import StringIO
import pytest
from flask.logging import default_handler
from flask.logging import has_level_handler
from flask.logging import wsgi_errors_stream
@pytest.fixture(autouse=True)
def reset_logging(pytestconfig):
root_handlers = logging.root.handlers[:]
logging.root.handlers = []
root_level = logging.root.level
logger = logging.getLogger("flask_test")
logger.handlers = []
logger.setLevel(logging.NOTSET)
logging_plugin = pytestconfig.pluginmanager.unregister(name="logging-plugin")
yield
logging.root.handlers[:] = root_handlers
logging.root.setLevel(root_level)
logger.handlers = []
logger.setLevel(logging.NOTSET)
if logging_plugin:
pytestconfig.pluginmanager.register(logging_plugin, "logging-plugin")
def test_logger(app):
assert app.logger.name == "flask_test"
assert app.logger.level == logging.NOTSET
assert app.logger.handlers == [default_handler]
def test_logger_debug(app):
app.debug = True
assert app.logger.level == logging.DEBUG
assert app.logger.handlers == [default_handler]
def test_existing_handler(app):
logging.root.addHandler(logging.StreamHandler())
assert app.logger.level == logging.NOTSET
assert not app.logger.handlers
def test_wsgi_errors_stream(app, client):
@app.route("/")
def index():
app.logger.error("test")
return ""
stream = StringIO()
client.get("/", errors_stream=stream)
assert "ERROR in test_logging: test" in stream.getvalue()
assert wsgi_errors_stream._get_current_object() is sys.stderr
with app.test_request_context(errors_stream=stream):
assert wsgi_errors_stream._get_current_object() is stream
def test_has_level_handler():
logger = logging.getLogger("flask.app")
assert not has_level_handler(logger)
handler = logging.StreamHandler()
logging.root.addHandler(handler)
assert has_level_handler(logger)
logger.propagate = False
assert not has_level_handler(logger)
logger.propagate = True
handler.setLevel(logging.ERROR)
assert not has_level_handler(logger)
def test_log_view_exception(app, client):
@app.route("/")
def index():
raise Exception("test")
app.testing = False
stream = StringIO()
rv = client.get("/", errors_stream=stream)
assert rv.status_code == 500
assert rv.data
err = stream.getvalue()
assert "Exception on / [GET]" in err
assert "Exception: test" in err
Domain
Subdomains
Functions
Dependencies
- flask.logging
- io
- logging
- pytest
- sys
Source
Frequently Asked Questions
What does test_logging.py do?
test_logging.py is a source file in the flask codebase, written in python. It belongs to the ApplicationCore domain, AppLifeCycle subdomain.
What functions are defined in test_logging.py?
test_logging.py defines 7 function(s): reset_logging, test_existing_handler, test_has_level_handler, test_log_view_exception, test_logger, test_logger_debug, test_wsgi_errors_stream.
What does test_logging.py depend on?
test_logging.py imports 5 module(s): flask.logging, io, logging, pytest, sys.
Where is test_logging.py in the architecture?
test_logging.py is located at tests/test_logging.py (domain: ApplicationCore, subdomain: AppLifeCycle, directory: tests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free