__init__.py
This file
Path
tests/__init__.py
62 lines · 1.6 KiB · Python
Last changed by
Remove old helper functionMarkus Unterwaditzerbefore adoption4ea4ea7
History of this fileTake it
1# -*- coding: utf-8 -*-2"""3 tests4 ~~~~~~~~~~~~~~~56 Tests Flask itself. The majority of Flask is already tested7 as part of Werkzeug.89 :copyright: (c) 2014 by Armin Ronacher.10 :license: BSD, see LICENSE for more details.11"""1213from __future__ import print_function1415import os16import sys17import warnings18from functools import update_wrapper19from contextlib import contextmanager20from flask._compat import StringIO212223@contextmanager24def catch_warnings():25 """Catch warnings in a with block in a list"""26 # make sure deprecation warnings are active in tests27 warnings.simplefilter('default', category=DeprecationWarning)2829 filters = warnings.filters30 warnings.filters = filters[:]31 old_showwarning = warnings.showwarning32 log = []3334 def showwarning(message, category, filename, lineno, file=None, line=None):35 log.append(locals())36 try:37 warnings.showwarning = showwarning38 yield log39 finally:40 warnings.filters = filters41 warnings.showwarning = old_showwarning424344@contextmanager45def catch_stderr():46 """Catch stderr in a StringIO"""47 old_stderr = sys.stderr48 sys.stderr = rv = StringIO()49 try:50 yield rv51 finally:52 sys.stderr = old_stderr535455def emits_module_deprecation_warning(f):56 def new_f(self, *args, **kwargs):57 with catch_warnings() as log:58 f(self, *args, **kwargs)59 assert log, 'expected deprecation warning'60 for entry in log:61 assert 'Modules are deprecated' in str(entry['message'])62 return update_wrapper(new_f, f)