DRYing up the test suite using pytest fixtures (#2306)

* add fixtures to conftest.py

* use fixtures in test_appctx.py

* use fixtures in test_blueprints.py

* use fixtures in test_depreciations.py

* use fixtures in test_regressions.py

* use fixtures in test_reqctx.py

* use fixtures in test_templating.py

* use fixtures in test_user_error_handler.py

* use fixtures in test_views.py

* use fixtures in test_basics.py

* use fixtures in test_helpers.py

* use fixtures in test_testing.py

* update conftest.py

* make docstrings  PEP-257 compliant

* cleanup

* switch dictonary format

* use pytest parameterization for test_json_as_unicode
This commit is contained in:
Christian Stade-Schuldt 2017-05-23 15:18:39 -07:00 committed by David Lord
parent 81c2440a05
commit 5b0b9717da
12 changed files with 1004 additions and 979 deletions

View file

@ -8,8 +8,7 @@ from werkzeug.exceptions import (
import flask
def test_error_handler_no_match():
app = flask.Flask(__name__)
def test_error_handler_no_match(app, client):
class CustomException(Exception):
pass
@ -31,15 +30,12 @@ def test_error_handler_no_match():
def key_error():
raise KeyError()
c = app.test_client()
assert c.get('/custom').data == b'custom'
assert c.get('/keyerror').data == b'KeyError'
app.testing = False
assert client.get('/custom').data == b'custom'
assert client.get('/keyerror').data == b'KeyError'
def test_error_handler_subclass():
app = flask.Flask(__name__)
def test_error_handler_subclass(app):
class ParentException(Exception):
pass
@ -78,9 +74,7 @@ def test_error_handler_subclass():
assert c.get('/child-registered').data == b'child-registered'
def test_error_handler_http_subclass():
app = flask.Flask(__name__)
def test_error_handler_http_subclass(app):
class ForbiddenSubclassRegistered(Forbidden):
pass
@ -116,7 +110,7 @@ def test_error_handler_http_subclass():
assert c.get('/forbidden-registered').data == b'forbidden-registered'
def test_error_handler_blueprint():
def test_error_handler_blueprint(app):
bp = flask.Blueprint('bp', __name__)
@bp.errorhandler(500)
@ -127,8 +121,6 @@ def test_error_handler_blueprint():
def bp_test():
raise InternalServerError()
app = flask.Flask(__name__)
@app.errorhandler(500)
def app_exception_handler(e):
return 'app-error'