conftest.py
This file
Path
examples/tutorial/tests/conftest.py
62 lines · 1.4 KiB · Python
Last changed by
Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
History of this fileTake it
The walk stopped after 200 commits: lines older than e08bcf9 point at it.
Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 1–4why, one step back1import os2import tempfile34import pytestMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
line 5why, one step back5Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
line 6why, one step back6from flaskr import create_appMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
lines 7–8why, one step back7from flaskr.db import get_db8from flaskr.db import init_dbFix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 9–10why, one step back910# read in SQL for populating test dataMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
lines 11–12why, one step back11with open(os.path.join(os.path.dirname(__file__), "data.sql"), "rb") as f:12 _data_sql = f.read().decode("utf8")Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 13–20why, one step back131415@pytest.fixture16def app():17 """Create and configure a new app instance for each test."""18 # create a temporary file to isolate the database for each test19 db_fd, db_path = tempfile.mkstemp()20 # create the app with common test configMerge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 21why, one step back21 app = create_app({"TESTING": True, "DATABASE": db_path})Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 22–46why, one step back2223 # create the database and load test data24 with app.app_context():25 init_db()26 get_db().executescript(_data_sql)2728 yield app2930 # close and remove the temporary database31 os.close(db_fd)32 os.unlink(db_path)333435@pytest.fixture36def client(app):37 """A test client for the app."""38 return app.test_client()394041@pytest.fixture42def runner(app):43 """A test runner for the app's Click commands."""44 return app.test_cli_runner()4546Merge pull request #3554 from pallets/drop-python2David Lordbefore adoptioncd8a374
line 47why, one step back47class AuthActions:Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 48–50why, one step back48 def __init__(self, client):49 self._client = client50Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 51why, one step back51 def login(self, username="test", password="test"):Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
line 52why, one step back52 return self._client.post(Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 53why, one step back53 "/auth/login", data={"username": username, "password": password}Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 54–56why, one step back54 )5556 def logout(self):Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032
line 57why, one step back57 return self._client.get("/auth/logout")Fix #2935: Copy current session object in copy_current_request_context (#2936)Dave Chevellbefore adoptione08bcf9
lines 58–62why, one step back585960@pytest.fixture61def auth(client):62 return AuthActions(client)