{"action":"created","issue":{"url":"https://api.github.com/repos/pallets/flask/issues/2949","repository_url":"https://api.github.com/repos/pallets/flask","labels_url":"https://api.github.com/repos/pallets/flask/issues/2949/labels{/name}","comments_url":"https://api.github.com/repos/pallets/flask/issues/2949/comments","events_url":"https://api.github.com/repos/pallets/flask/issues/2949/events","html_url":"https://github.com/pallets/flask/issues/2949","id":371384627,"node_id":"MDU6SXNzdWUzNzEzODQ2Mjc=","number":2949,"title":"Documentation \"Testing Flask Applications\" should show client teardown","user":{"login":"ncraike","id":1109269,"node_id":"MDQ6VXNlcjExMDkyNjk=","avatar_url":"https://avatars3.githubusercontent.com/u/1109269?v=4","gravatar_id":"","url":"https://api.github.com/users/ncraike","html_url":"https://github.com/ncraike","followers_url":"https://api.github.com/users/ncraike/followers","following_url":"https://api.github.com/users/ncraike/following{/other_user}","gists_url":"https://api.github.com/users/ncraike/gists{/gist_id}","starred_url":"https://api.github.com/users/ncraike/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ncraike/subscriptions","organizations_url":"https://api.github.com/users/ncraike/orgs","repos_url":"https://api.github.com/users/ncraike/repos","events_url":"https://api.github.com/users/ncraike/events{/privacy}","received_events_url":"https://api.github.com/users/ncraike/received_events","type":"User","site_admin":false},"labels":[{"id":32876,"node_id":"MDU6TGFiZWwzMjg3Ng==","url":"https://api.github.com/repos/pallets/flask/labels/docs","name":"docs","color":"0e8a16","default":false},{"id":170296925,"node_id":"MDU6TGFiZWwxNzAyOTY5MjU=","url":"https://api.github.com/repos/pallets/flask/labels/good%20first%20issue","name":"good first issue","color":"fbca04","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-18T06:50:46Z","updated_at":"2018-10-28T01:00:52Z","closed_at":null,"author_association":"NONE","body":"The `flask.testing` `FlaskClient` has clean-up which only happens if you use the test client in a `with` block:\r\n\r\n```python\r\nclass FlaskClient(Client):\r\n\r\n    # ...\r\n\r\n    def __exit__(self, exc_type, exc_value, tb):\r\n        self.preserve_context = False\r\n\r\n        # on exit we want to clean up earlier.  Normally the request context\r\n        # stays preserved until the next request in the same thread comes\r\n        # in.  See RequestGlobals.push() for the general behavior.\r\n        top = _request_ctx_stack.top\r\n        if top is not None and top.preserved:\r\n            top.pop()\r\n```\r\n\r\nThis is described in the API documentation for [`app.test_client()`](http://flask.pocoo.org/docs/0.12/api/#flask.Flask.test_client), but isn't mentioned in the [Testing Flask Applications](http://flask.pocoo.org/docs/1.0/testing/) chapter of the documentation, and the \"testing skeleton\" code doesn't use `test_client()` in a `with` block:\r\n\r\n```python\r\n@pytest.fixture\r\ndef client():\r\n    db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()\r\n    flaskr.app.config['TESTING'] = True\r\n    client = flaskr.app.test_client()\r\n\r\n    with flaskr.app.app_context():\r\n        flaskr.init_db()\r\n\r\n    yield client\r\n```\r\n\r\nThe [Testing Flask Applications](http://flask.pocoo.org/docs/1.0/testing/) chapter should demonstrate using the test client in _some way_ which does teardown.\r\n\r\nI raise this because I used the skeleton code as basis for a `pytest` fixture, and I _believe_ I've run into intermittent test failure issues which are caused by request context leaking between tests."},"comment":{"url":"https://api.github.com/repos/pallets/flask/issues/comments/433667664","html_url":"https://github.com/pallets/flask/issues/2949#issuecomment-433667664","issue_url":"https://api.github.com/repos/pallets/flask/issues/2949","id":433667664,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzY2NzY2NA==","user":{"login":"Albert-Guan","id":20601182,"node_id":"MDQ6VXNlcjIwNjAxMTgy","avatar_url":"https://avatars3.githubusercontent.com/u/20601182?v=4","gravatar_id":"","url":"https://api.github.com/users/Albert-Guan","html_url":"https://github.com/Albert-Guan","followers_url":"https://api.github.com/users/Albert-Guan/followers","following_url":"https://api.github.com/users/Albert-Guan/following{/other_user}","gists_url":"https://api.github.com/users/Albert-Guan/gists{/gist_id}","starred_url":"https://api.github.com/users/Albert-Guan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Albert-Guan/subscriptions","organizations_url":"https://api.github.com/users/Albert-Guan/orgs","repos_url":"https://api.github.com/users/Albert-Guan/repos","events_url":"https://api.github.com/users/Albert-Guan/events{/privacy}","received_events_url":"https://api.github.com/users/Albert-Guan/received_events","type":"User","site_admin":false},"created_at":"2018-10-28T01:00:52Z","updated_at":"2018-10-28T01:00:52Z","author_association":"NONE","body":"Hi! I just start using flask and I am working on this issue. I want to test if my changes work, so I follow the \r\n[http://flask.pocoo.org/docs/1.0/testing/](url)\r\nBut in this line: `from flaskr import flaskr` it fails. \r\nI didn't see a **flaskr** under **flaskr module** in the **examples/tutorial directory. Is there any way to to test the codes?"}}
{"actor":{"display_login":"Albert-Guan"}}