diff --git a/docs/testing.rst b/docs/testing.rst index ed9f0b03..8f3e4f2d 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -54,12 +54,11 @@ the application for testing and initializes a new database:: def client(): db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp() flaskr.app.config['TESTING'] = True - client = flaskr.app.test_client() - - with flaskr.app.app_context(): - flaskr.init_db() - - yield client + + with flaskr.app.test_client() as client: + with flaskr.app.app_context(): + flaskr.init_db() + yield client os.close(db_fd) os.unlink(flaskr.app.config['DATABASE'])