subclassing.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. """
  3. flask.testsuite.subclassing
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Test that certain behavior of flask can be customized by
  6. subclasses.
  7. :copyright: (c) 2011 by Armin Ronacher.
  8. :license: BSD, see LICENSE for more details.
  9. """
  10. import flask
  11. import unittest
  12. from logging import StreamHandler
  13. from flask.testsuite import FlaskTestCase
  14. from flask._compat import StringIO
  15. class FlaskSubclassingTestCase(FlaskTestCase):
  16. def test_suppressed_exception_logging(self):
  17. class SuppressedFlask(flask.Flask):
  18. def log_exception(self, exc_info):
  19. pass
  20. out = StringIO()
  21. app = SuppressedFlask(__name__)
  22. app.logger_name = 'flask_tests/test_suppressed_exception_logging'
  23. app.logger.addHandler(StreamHandler(out))
  24. @app.route('/')
  25. def index():
  26. 1 // 0
  27. rv = app.test_client().get('/')
  28. self.assert_equal(rv.status_code, 500)
  29. self.assert_in(b'Internal Server Error', rv.data)
  30. err = out.getvalue()
  31. self.assert_equal(err, '')
  32. def suite():
  33. suite = unittest.TestSuite()
  34. suite.addTest(unittest.makeSuite(FlaskSubclassingTestCase))
  35. return suite