Merge pull request #3240 from ultimecia7/docfix

Fix testing documentation to demonstrate using test client with teardown
This commit is contained in:
David Lord 2019-05-31 14:06:54 -04:00 committed by GitHub
commit 6e995f2379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -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'])