| 210 | |
| 211 | |
| 212 | def test_test_client_context_binding(app, client): |
| 213 | app.testing = False |
| 214 | |
| 215 | @app.route("/") |
| 216 | def index(): |
| 217 | flask.g.value = 42 |
| 218 | return "Hello World!" |
| 219 | |
| 220 | @app.route("/other") |
| 221 | def other(): |
| 222 | raise ZeroDivisionError |
| 223 | |
| 224 | with client: |
| 225 | resp = client.get("/") |
| 226 | assert flask.g.value == 42 |
| 227 | assert resp.data == b"Hello World!" |
| 228 | assert resp.status_code == 200 |
| 229 | |
| 230 | with client: |
| 231 | resp = client.get("/other") |
| 232 | assert not hasattr(flask.g, "value") |
| 233 | assert b"Internal Server Error" in resp.data |
| 234 | assert resp.status_code == 500 |
| 235 | flask.g.value = 23 |
| 236 | |
| 237 | with pytest.raises(RuntimeError): |
| 238 | flask.g.value # noqa: B018 |
| 239 | |
| 240 | |
| 241 | def test_reuse_client(client): |