forked from orbit-oss/flask
clean up pytest.raises tests
This commit is contained in:
parent
ef7d01f0a0
commit
ef6c2b9e4a
4 changed files with 25 additions and 22 deletions
|
|
@ -120,7 +120,7 @@ def test_app_tearing_down_with_unhandled_exception(app, client):
|
|||
def index():
|
||||
raise Exception("dummy")
|
||||
|
||||
with pytest.raises(Exception):
|
||||
with pytest.raises(Exception, match="dummy"):
|
||||
with app.app_context():
|
||||
client.get("/")
|
||||
|
||||
|
|
|
|||
|
|
@ -150,10 +150,7 @@ def test_request_dispatching(app, client):
|
|||
|
||||
def test_disallow_string_for_allowed_methods(app):
|
||||
with pytest.raises(TypeError):
|
||||
|
||||
@app.route("/", methods="GET POST")
|
||||
def index():
|
||||
return "Hey"
|
||||
app.add_url_rule("/", methods="GET POST", endpoint="test")
|
||||
|
||||
|
||||
def test_url_mapping(app, client):
|
||||
|
|
@ -937,8 +934,9 @@ def test_baseexception_error_handling(app, client):
|
|||
def broken_func():
|
||||
raise KeyboardInterrupt()
|
||||
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
client.get("/")
|
||||
with client:
|
||||
with pytest.raises(KeyboardInterrupt):
|
||||
client.get("/")
|
||||
|
||||
ctx = flask._request_ctx_stack.top
|
||||
assert ctx.preserved
|
||||
|
|
@ -1243,20 +1241,25 @@ def test_response_type_errors():
|
|||
|
||||
with pytest.raises(TypeError) as e:
|
||||
c.get("/none")
|
||||
assert "returned None" in str(e.value)
|
||||
assert "from_none" in str(e.value)
|
||||
|
||||
assert "returned None" in str(e.value)
|
||||
assert "from_none" in str(e.value)
|
||||
|
||||
with pytest.raises(TypeError) as e:
|
||||
c.get("/small_tuple")
|
||||
assert "tuple must have the form" in str(e.value)
|
||||
|
||||
pytest.raises(TypeError, c.get, "/large_tuple")
|
||||
assert "tuple must have the form" in str(e.value)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
c.get("/large_tuple")
|
||||
|
||||
with pytest.raises(TypeError) as e:
|
||||
c.get("/bad_type")
|
||||
assert "it was a bool" in str(e.value)
|
||||
|
||||
pytest.raises(TypeError, c.get, "/bad_wsgi")
|
||||
assert "it was a bool" in str(e.value)
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
c.get("/bad_wsgi")
|
||||
|
||||
|
||||
def test_make_response(app, req_ctx):
|
||||
|
|
@ -1674,11 +1677,9 @@ def test_debug_mode_complains_after_first_request(app, client):
|
|||
|
||||
assert not app.got_first_request
|
||||
assert client.get("/").data == b"Awesome"
|
||||
with pytest.raises(AssertionError) as e:
|
||||
|
||||
@app.route("/foo")
|
||||
def broken():
|
||||
return "Meh"
|
||||
with pytest.raises(AssertionError) as e:
|
||||
app.add_url_rule("/foo", endpoint="late")
|
||||
|
||||
assert "A setup function was called" in str(e.value)
|
||||
|
||||
|
|
|
|||
|
|
@ -305,9 +305,9 @@ def test_lazy_load_error(monkeypatch):
|
|||
|
||||
lazy = DispatchingApp(bad_load, use_eager_loading=False)
|
||||
|
||||
with pytest.raises(BadExc):
|
||||
# reduce flakiness by waiting for the internal loading lock
|
||||
with lazy._lock:
|
||||
# reduce flakiness by waiting for the internal loading lock
|
||||
with lazy._lock:
|
||||
with pytest.raises(BadExc):
|
||||
lazy._flush_bg_loading_exception()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -133,9 +133,11 @@ def test_config_from_class():
|
|||
def test_config_from_envvar(monkeypatch):
|
||||
monkeypatch.setattr("os.environ", {})
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
app.config.from_envvar("FOO_SETTINGS")
|
||||
assert "'FOO_SETTINGS' is not set" in str(e.value)
|
||||
|
||||
assert "'FOO_SETTINGS' is not set" in str(e.value)
|
||||
assert not app.config.from_envvar("FOO_SETTINGS", silent=True)
|
||||
|
||||
monkeypatch.setattr(
|
||||
|
|
@ -147,8 +149,8 @@ def test_config_from_envvar(monkeypatch):
|
|||
|
||||
def test_config_from_envvar_missing(monkeypatch):
|
||||
monkeypatch.setattr("os.environ", {"FOO_SETTINGS": "missing.cfg"})
|
||||
app = flask.Flask(__name__)
|
||||
with pytest.raises(IOError) as e:
|
||||
app = flask.Flask(__name__)
|
||||
app.config.from_envvar("FOO_SETTINGS")
|
||||
msg = str(e.value)
|
||||
assert msg.startswith(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue