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 09392e0 point at it.
Merge remote-tracking branch 'origin/1.0.x'David Lordbefore adoption09392e0
lines 1–4why, one step back1import os2import tempfile34import pytestMerge pull request #3246 from pallets/reorder-importsDavid Lordbefore adoption3db4697
line 5why, one step back5Merge remote-tracking branch 'origin/1.0.x'David Lordbefore adoption09392e0
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_dbMerge remote-tracking branch 'origin/1.0.x'David Lordbefore adoption09392e0
lines 9–46why, one step back910# read in SQL for populating test data11with open(os.path.join(os.path.dirname(__file__), "data.sql"), "rb") as f:12 _data_sql = f.read().decode("utf8")131415@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 config21 app = create_app({"TESTING": True, "DATABASE": db_path})2223 # 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:Merge remote-tracking branch 'origin/1.0.x'David Lordbefore adoption09392e0
lines 48–62why, one step back48 def __init__(self, client):49 self._client = client5051 def login(self, username="test", password="test"):52 return self._client.post(53 "/auth/login", data={"username": username, "password": password}54 )5556 def logout(self):57 return self._client.get("/auth/logout")585960@pytest.fixture61def auth(client):62 return AuthActions(client)