1414sys .path .insert (0 , os .path .join (
1515 os .path .abspath (os .path .dirname (__file__ )),
1616 ".." , ".env" , "mailboxer" ))
17- from flask_app .app import app
17+ from flask_app .app import create_app
1818from flask_app import models
1919
2020def pytest_addoption (parser ):
@@ -26,21 +26,23 @@ def db_engine(request):
2626 tmpdir = tempfile .mkdtemp ()
2727 subprocess .check_call ("pg_ctl init -D {0} -w" .format (tmpdir ), shell = True )
2828 subprocess .check_call ("pg_ctl start -D {0} -w" .format (tmpdir ), shell = True )
29+
2930 @request .addfinalizer
3031 def finalize ():
3132 subprocess .check_call ("pg_ctl stop -D {0} -w -m immediate" .format (tmpdir ), shell = True )
3233 shutil .rmtree (tmpdir )
3334
3435 subprocess .check_call ("createdb mailboxer" , shell = True )
3536
36- models .db .session .close ()
37- models .db .drop_all ()
38- models .db .create_all ()
37+ with create_app ().app_context ():
38+ models .db .session .close ()
39+ models .db .drop_all ()
40+ models .db .create_all ()
3941
4042
4143@pytest .fixture (scope = "session" )
4244def mailboxer_url (request , db_engine ):
43- loopback = FlaskLoopback (app )
45+ loopback = FlaskLoopback (create_app () )
4446 hostname = str (uuid .uuid1 ())
4547 loopback .activate_address ((hostname , 80 ))
4648 @request .addfinalizer
0 commit comments