Skip to content
Myr

clean up pytest.raises tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent ef7d01f · Browse files · 4 files+25 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+25 added−22 removed

  • tests:+25 added−22 removed

4 files+25 added−22 removed

modified:tests/test_appctx.py+1 added-1 removed
118 unmodified lines
119 @app.route("/")120 def index():121 raise Exception("dummy")122123 with pytest.raises(Exception):123 with pytest.raises(Exception, match="dummy"):124 with app.app_context():125 client.get("/")126127 assert len(cleanup_stuff) == 1
83 unmodified lines
modified:tests/test_basic.py+17 added-16 removed
148 unmodified lines
149150151def test_disallow_string_for_allowed_methods(app):152 with pytest.raises(TypeError):153 app.add_url_rule("/", methods="GET POST", endpoint="test")154154 @app.route("/", methods="GET POST")155 def index():156 return "Hey"155158156def test_url_mapping(app, client):157 random_uuid4 = "7eb41166-9ebf-4d26-b771-ea3f54f8b383"158159 def index():
773 unmodified lines
933 @app.route("/")934 def broken_func():935 raise KeyboardInterrupt()936937 with client:940 with pytest.raises(KeyboardInterrupt):941 client.get("/")938 with pytest.raises(KeyboardInterrupt):939 client.get("/")940941 ctx = flask._request_ctx_stack.top942 assert ctx.preserved943 assert type(ctx._preserved_exc) is KeyboardInterrupt
296 unmodified lines
1240 c = app.test_client()12411242 with pytest.raises(TypeError) as e:1243 c.get("/none")1246 assert "returned None" in str(e.value)1247 assert "from_none" in str(e.value)12441245 assert "returned None" in str(e.value)1246 assert "from_none" in str(e.value)12471248 with pytest.raises(TypeError) as e:1249 c.get("/small_tuple")1251 assert "tuple must have the form" in str(e.value)12501253 pytest.raises(TypeError, c.get, "/large_tuple")1251 assert "tuple must have the form" in str(e.value)12521253 with pytest.raises(TypeError):1254 c.get("/large_tuple")12551256 with pytest.raises(TypeError) as e:1257 c.get("/bad_type")1257 assert "it was a bool" in str(e.value)12581259 pytest.raises(TypeError, c.get, "/bad_wsgi")1259 assert "it was a bool" in str(e.value)12601261 with pytest.raises(TypeError):1262 c.get("/bad_wsgi")126312641265def test_make_response(app, req_ctx):1266 rv = flask.make_response()1267 assert rv.status_code == 2001268 assert rv.data == b""
407 unmodified lines
1676 return "Awesome"16771678 assert not app.got_first_request1679 assert client.get("/").data == b"Awesome"16801681 with pytest.raises(AssertionError) as e:1682 app.add_url_rule("/foo", endpoint="late")16831679 @app.route("/foo")1680 def broken():1681 return "Meh"16821684 assert "A setup function was called" in str(e.value)16851686 app.debug = False1687
349 unmodified lines
modified:tests/test_cli.py+3 added-3 removed
303 unmodified lines
304 raise BadExc305306 lazy = DispatchingApp(bad_load, use_eager_loading=False)307308 with pytest.raises(BadExc):309 # reduce flakiness by waiting for the internal loading lock310 with lazy._lock:308 # reduce flakiness by waiting for the internal loading lock309 with lazy._lock:310 with pytest.raises(BadExc):311 lazy._flush_bg_loading_exception()312313314def test_with_appcontext(runner):
345 unmodified lines
modified:tests/test_config.py+4 added-2 removed
131 unmodified lines
132133def test_config_from_envvar(monkeypatch):134 monkeypatch.setattr("os.environ", {})135 app = flask.Flask(__name__)136137 with pytest.raises(RuntimeError) as e:138 app.config.from_envvar("FOO_SETTINGS")139138 assert "'FOO_SETTINGS' is not set" in str(e.value)140 assert "'FOO_SETTINGS' is not set" in str(e.value)141 assert not app.config.from_envvar("FOO_SETTINGS", silent=True)142143 monkeypatch.setattr(144 "os.environ", {"FOO_SETTINGS": f"{__file__.rsplit('.', 1)[0]}.py"}
3 unmodified lines
148149150def test_config_from_envvar_missing(monkeypatch):151 monkeypatch.setattr("os.environ", {"FOO_SETTINGS": "missing.cfg"})152 app = flask.Flask(__name__)153 with pytest.raises(IOError) as e:151 app = flask.Flask(__name__)154 app.config.from_envvar("FOO_SETTINGS")155 msg = str(e.value)156 assert msg.startswith(157 "[Errno 2] Unable to load configuration file (No such file or directory):"
97 unmodified lines