-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
50 lines (34 loc) · 899 Bytes
/
conftest.py
File metadata and controls
50 lines (34 loc) · 899 Bytes
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
40
41
42
43
44
45
46
47
48
49
50
import os
import pathlib
import pytest
from src.app import create_app
from src.extensions import db as _db
@pytest.fixture
def app():
CONFIG_PATH = os.path.join(
pathlib.Path(__file__).parent.absolute(), 'application_test.cfg')
app = create_app(CONFIG_PATH)
ctx = app.app_context()
ctx.push()
def teardown():
ctx.pop()
return app
@pytest.fixture
def client(app):
with app.test_client() as c:
yield c
@pytest.fixture
def db(app):
TESTDB_PATH = os.path.join(
pathlib.Path(__file__).parent.absolute(),
app.config['SQLALCHEMY_DATABASE_URI'].split('/')[-1])
if os.path.exists(TESTDB_PATH):
os.unlink(TESTDB_PATH)
print(TESTDB_PATH)
def teardown():
db.drop_all()
pathlib.Path.unlink(TESTDB_PATH)
os.remove(TESTDB_PATH)
_db.app = app
_db.create_all()
return _db