Skip to content
Myr

test_db.py

This file

Path

examples/tutorial/tests/test_db.py

28 lines · 617 bytes · Python

Last changed by

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

History of this file

Take it

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

lines 1–12why, one step back
1import sqlite3
23import pytest4from flaskr.db import get_db567def test_get_close_db(app):8 with app.app_context():9 db = get_db()10 assert db is get_db()1112 with pytest.raises(sqlite3.ProgrammingError) as e:

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

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

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

line 14why, one step back
14

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

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

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

lines 16–24why, one step back
16
1718def test_init_db_command(runner, monkeypatch):19 class Recorder(object):20 called = False2122 def fake_init_db():23 Recorder.called = True24

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

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

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

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