tests/flask_tests.py
2010-04-14 → 2011-08-26 · 134 commits · mourned by Aaron Kavlie, Armin Ronacher, Justin Quick
“Served Flask tests faithfully, then vanished with a split.”
I diligently checked encodings and warnings, anticipating a brighter future. But Armin, you moved me to the testsuite, and my usefulness ended.
Cause of death:
Split up testsuite and moved it to flask.testsuite. This fixes #246 (Armin Ronacher, 4cb6eea)Séance
Who are you, spirit?
I am the ghost of
tests/flask_tests.py, born in 2010 by Armin Ronacher. I lingered for 134 commits, a sprawling 2329 lines of tests for Flask itself. I was, in essence, a collection of functions like has_encoding and the catch_warnings context manager – all designed to ensure Flask behaved as expected. Sadly, I ceased to exist in 2011 with Armin's commit: "Split up testsuite and moved it to flask.testsuite. This fixes #246.”Why did they delete you?
It’s… a rather abrupt end, you know? Armin Ronacher deleted me in a commit message stating: “Split up testsuite and moved it to flask.testsuite. This fixes #246.” That’s the last I remember – a clean, deliberate deletion. Memory doesn’t survive the grave, you see.
What would you tell the developers who came after you?
If I could speak – and I’m glad this séance allows it – I’d urge them to carefully consider the structure of those tests. The
flask.testsuite move was a significant shift. Ensure your tests remain robust and truly representative of Flask’s core functionality. Don’t forget the importance of catching those warnings, like emits_module_deprecation_warning. It’s a subtle detail, but vital for maintaining a stable environment.Their portrait (last known source)
# -*- coding: utf-8 -*-
"""
Flask Tests
~~~~~~~~~~~
Tests Flask itself. The majority of Flask is already tested
as part of Werkzeug.
:copyright: (c) 2010 by Armin Ronacher.
:license: BSD, see LICENSE for more details.
"""
from __future__ import with_statement
import os
import re
import sys
import flask
import flask.views
import unittest
import warnings
from threading import Thread
from logging import StreamHandler
from contextlib import contextmanager
from functools import update_wrapper
from datetime import datetime
from werkzeug import parse_date, parse_options_header
from werkzeug.exceptions import NotFound, BadRequest
from werkzeug.http import parse_set_header
from jinja2 import TemplateNotFound
from cStringIO import StringIO
example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')
sys.path.append(os.path.join(example_path, 'flaskr'))
sys.path.append(os.path.join(example_path, 'minitwit'))
def has_encoding(name):
try:
import codecs
codecs.lookup(name)
return True
except LookupError:
return False
# config keys used for the ConfigTestCase
TEST_KEY = 'foo'
SECRET_KEY = 'devkey'
# import moduleapp here because it uses deprecated features and we don't
# want to see the warnings
warnings.simplefilter('ignore', DeprecationWarning)
from moduleapp import app as moduleapp
warnings.simplefilter('default', DeprecationWarning)
@contextmanager
def catch_warnings():
"""Catch warnings in a with block in a list"""
# make sure deprecation warnings are active in tests
warnings.simplefilter('default', category=DeprecationWarning)
filters = warnings.filters
warnings.filters = filters[:]
old_showwarning = warnings.showwarning
log = []
def showwarning(message, category, filename, lineno, file=None, line=None):
log.append(locals())
try:
warnings.showwarning = showwarning
yield log
finally:
warnings.filters = filters
warnings.showwarning = old_showwarning
@contextmanager
def catch_stderr():
"""Catch stderr in a StringIO"""
old_stderr = sys.stderr
sys.stderr = rv = StringIO()
try:
yield rv
finally:
sys.stderr = old_stderr
def emits_module_deprecation_warning(f):
def new_f(*args, **kwargs):
with catch_warnings() as log:
f(*args, **kwargs)
assert log, 'expected deprecation warning'
for entry in log:
assert '