-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
71 lines (47 loc) · 1.3 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pytest
import main
from config import JudgeConfig
from main import db as app_db
@pytest.fixture(scope='session')
def app(request):
app = main.app
app.config.from_object(JudgeConfig(testing=True))
ctx = app.app_context()
ctx.push()
def teardown():
ctx.pop()
request.addfinalizer(teardown)
return app
@pytest.fixture(scope='function')
def client(app, request_context):
return app.test_client()
@pytest.fixture(scope='class')
def db(request, app):
app_db.reflect() # Weird hack
app_db.drop_all()
app_db.create_all()
def teardown():
app_db.session.close()
app_db.drop_all()
request.addfinalizer(teardown)
return app_db
@pytest.fixture(scope='function')
def request_context(request, app):
ctx = app.test_request_context()
ctx.push()
def teardown():
ctx.pop()
request.addfinalizer(teardown)
@pytest.fixture(scope='class')
def session(request, db):
connection = db.engine.connect()
transaction = connection.begin()
options = dict(bind=connection, binds={})
session = db.create_scoped_session(options=options)
db.session = session
def teardown():
transaction.rollback()
connection.close()
session.remove()
request.addfinalizer(teardown)
return session