/
conftest.py
39 lines (30 loc) · 942 Bytes
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import tempfile
import pytest
from demo.app import create_app
from demo.extensions import db
class Client(object):
def __init__(self):
config = {'TESTING': True,
'WTF_CSRF_ENABLED': False,
'WTF_CSRF_CHECK_DEFAULT': False,
'SECRET_KEY': 'secret-key-for-test',
}
self.db_fd, self.db_file = tempfile.mkstemp()
config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///%s' % self.db_file
self.app = create_app(config)
self.client = self.app.test_client()
db.create_all()
self.db = db
def clean(self):
self.db.session.remove()
self.db.drop_all()
os.close(self.db_fd)
os.unlink(self.db_file)
@pytest.fixture(scope='function')
def client(request):
client = Client()
request.addfinalizer(client.clean)
return client