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
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
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_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_suppressed_exception_logging(): class SuppressedFlask(flask.Flask): def log_exception(self, exc_info): pass out = StringIO() app = SuppressedFlask(__name__) @app.route('/') def index(): raise Exception('test') rv = app.test_client().get('/', errors_stream=out) assert rv.status_code == 500 assert b'Internal Server Error' in rv.data assert not out.getvalue()
def test_exception_logging(self): out = StringIO() app = flask.Flask(__name__) app.logger_name = 'flask_tests/test_exception_logging' app.logger.addHandler(StreamHandler(out)) @app.route('/') def index(): 1 // 0 rv = app.test_client().get('/') self.assert_equal(rv.status_code, 500) self.assert_in(b'Internal Server Error', rv.data) err = out.getvalue() self.assert_in('Exception on / [GET]', err) self.assert_in('Traceback (most recent call last):', err) self.assert_in('1 // 0', err) self.assert_in('ZeroDivisionError:', err)
def test_exception_logging(self): out = StringIO() app = flask.Flask(__name__) app.logger_name = "flask_tests/test_exception_logging" app.logger.addHandler(StreamHandler(out)) @app.route("/") def index(): 1 // 0 rv = app.test_client().get("/") self.assert_equal(rv.status_code, 500) self.assert_in(b"Internal Server Error", rv.data) err = out.getvalue() self.assert_in("Exception on / [GET]", err) self.assert_in("Traceback (most recent call last):", err) self.assert_in("1 // 0", err) self.assert_in("ZeroDivisionError:", err)
def test_exception_logging(self): out = StringIO() app = flask.Flask(__name__) app.config['LOGGER_HANDLER_POLICY'] = 'never' app.logger_name = 'flask_tests/test_exception_logging' app.logger.addHandler(StreamHandler(out)) @app.route('/') def index(): 1 // 0 rv = app.test_client().get('/') assert rv.status_code == 500 assert b'Internal Server Error' in rv.data err = out.getvalue() assert 'Exception on / [GET]' in err assert 'Traceback (most recent call last):' in err assert '1 // 0' in err assert 'ZeroDivisionError:' in err
def test_suppressed_exception_logging(): class SuppressedFlask(flask.Flask): def log_exception(self, exc_info): pass out = StringIO() app = SuppressedFlask(__name__) app.logger_name = 'flask_tests/test_suppressed_exception_logging' app.logger.addHandler(StreamHandler(out)) @app.route('/') def index(): 1 // 0 rv = app.test_client().get('/') assert rv.status_code == 500 assert b'Internal Server Error' in rv.data err = out.getvalue() assert err == ''
def test_exception_logging(self, app, client): out = StringIO() app.config['LOGGER_HANDLER_POLICY'] = 'never' app.logger_name = 'flask_tests/test_exception_logging' app.logger.addHandler(StreamHandler(out)) app.testing = False @app.route('/') def index(): 1 // 0 rv = client.get('/') assert rv.status_code == 500 assert b'Internal Server Error' in rv.data err = out.getvalue() assert 'Exception on / [GET]' in err assert 'Traceback (most recent call last):' in err assert '1 // 0' in err assert 'ZeroDivisionError:' in err