forked from orbit-oss/flask
Fix testing documentation to demonstrate using test client with teardown
This commit is contained in:
parent
99660cc409
commit
d981cc678a
1 changed files with 5 additions and 6 deletions
|
|
@ -54,12 +54,11 @@ the application for testing and initializes a new database.::
|
||||||
def client():
|
def client():
|
||||||
db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
|
db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
|
||||||
flaskr.app.config['TESTING'] = True
|
flaskr.app.config['TESTING'] = True
|
||||||
client = flaskr.app.test_client()
|
|
||||||
|
with flaskr.app.test_client() as client:
|
||||||
with flaskr.app.app_context():
|
with flaskr.app.app_context():
|
||||||
flaskr.init_db()
|
flaskr.init_db()
|
||||||
|
yield client
|
||||||
yield client
|
|
||||||
|
|
||||||
os.close(db_fd)
|
os.close(db_fd)
|
||||||
os.unlink(flaskr.app.config['DATABASE'])
|
os.unlink(flaskr.app.config['DATABASE'])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue