Skip to content
Myr

Merge pull request #4156 from yuxiaoy1/patch-4

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Improve the code example in testing docs

authored by David Lord · committed by GitHub · parents f353d12, 7b696e0 · Browse files · 1 file+7 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−6 removed

  • other:+7 added−6 removed

1 file+7 added−6 removed

modified:docs/testing.rst+7 added-6 removed
46 unmodified lines
4748 import pytest4950 from flaskr import create_app51 from flaskr.db import init_db525354 @pytest.fixture55 def client():55 db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()56 flaskr.app.config['TESTING'] = True56 db_fd, db_path = tempfile.mkstemp()57 app = create_app({'TESTING': True, 'DATABASE': db_path})5858 with flaskr.app.test_client() as client:59 with flaskr.app.app_context():60 flaskr.init_db()59 with app.test_client() as client:60 with app.app_context():61 init_db()62 yield client6364 os.close(db_fd)64 os.unlink(flaskr.app.config['DATABASE'])65 os.unlink(db_path)6667This client fixture will be called by each individual test. It gives us a68simple interface to the application, where we can trigger test requests to the69application. The client will also keep track of cookies for us.
394 unmodified lines