mirror of https://github.com/mitsuhiko/flask.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
863 B
47 lines
863 B
# -*- coding: utf-8 -*- |
|
""" |
|
Flaskr conftest |
|
~~~~~~~~~~~~ |
|
|
|
Defines fixtures for the Flaskr test suite. |
|
|
|
:copyright: (c) 2015 by Armin Ronacher. |
|
:license: BSD, see LICENSE for more details. |
|
""" |
|
import os |
|
import tempfile |
|
import pytest |
|
from flaskr.factory import create_app |
|
from flaskr.blueprints.flaskr import init_db |
|
|
|
|
|
@pytest.fixture |
|
def app(request): |
|
|
|
db_fd, temp_db_location = tempfile.mkstemp() |
|
config = { |
|
'DATABASE': temp_db_location, |
|
'TESTING': True, |
|
'DB_FD': db_fd |
|
} |
|
|
|
app = create_app(config=config) |
|
|
|
with app.app_context(): |
|
init_db() |
|
yield app |
|
|
|
|
|
@pytest.fixture |
|
def client(request, app): |
|
|
|
client = app.test_client() |
|
|
|
def teardown(): |
|
os.close(app.config['DB_FD']) |
|
os.unlink(app.config['DATABASE']) |
|
request.addfinalizer(teardown) |
|
|
|
return client |
|
|
|
|
|
|