| 165 | |
| 166 | |
| 167 | def test_context_refcounts(app, client): |
| 168 | called = [] |
| 169 | |
| 170 | @app.teardown_request |
| 171 | def teardown_req(error=None): |
| 172 | called.append("request") |
| 173 | |
| 174 | @app.teardown_appcontext |
| 175 | def teardown_app(error=None): |
| 176 | called.append("app") |
| 177 | |
| 178 | @app.route("/") |
| 179 | def index(): |
| 180 | with app_ctx: |
| 181 | with request_ctx: |
| 182 | pass |
| 183 | |
| 184 | assert flask.request.environ["werkzeug.request"] is not None |
| 185 | return "" |
| 186 | |
| 187 | res = client.get("/") |
| 188 | assert res.status_code == 200 |
| 189 | assert res.data == b"" |
| 190 | assert called == ["request", "app"] |
| 191 | |
| 192 | |
| 193 | def test_clean_pop(app): |