Skip to content
Myr

test_db.py

This file

Path

examples/tutorial/tests/test_db.py

29 lines · 618 bytes · Python

Last changed by

apply reorder-python-imports pre-commit configDavid Lordbefore adoption4348368

History of this file

Take it

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

lines 1–3why, one step back
1import sqlite3
23import pytest

apply reorder-python-imports pre-commit configDavid Lordbefore adoption4348368

line 4why, one step back
4

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

lines 5–13why, one step back
5from flaskr.db import get_db
678def test_get_close_db(app):9 with app.app_context():10 db = get_db()11 assert db is get_db()1213 with pytest.raises(sqlite3.ProgrammingError) as e:

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 14why, one step back
14 db.execute("SELECT 1")

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

line 15why, one step back
15

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

line 16why, one step back
16 assert "closed" in str(e)

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

lines 17–25why, one step back
17
1819def test_init_db_command(runner, monkeypatch):20 class Recorder(object):21 called = False2223 def fake_init_db():24 Recorder.called = True25

Merge pull request #3183 from singingwolfboy/pre-commitDavid Baumgoldbefore adoption1dda032

lines 26–28why, one step back
26 monkeypatch.setattr("flaskr.db.init_db", fake_init_db)
27 result = runner.invoke(args=["init-db"])28 assert "Initialized" in result.output

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

line 29why, one step back
29 assert Recorder.called