clean up pytest.raises tests
This commit is contained in:
parent
ef7d01f0a0
commit
ef6c2b9e4a
4 changed files with 25 additions and 22 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue