diff --git a/iebank_api/__init__.py b/iebank_api/__init__.py index fe760f9..3f3a2ed 100644 --- a/iebank_api/__init__.py +++ b/iebank_api/__init__.py @@ -26,7 +26,9 @@ db = SQLAlchemy(app) from iebank_api.models import Account -db.create_all() + +with app.app_context(): + db.create_all() CORS(app) from iebank_api import routes diff --git a/tests/conftest.py b/tests/conftest.py index 09697ab..e173e54 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,14 +3,17 @@ from iebank_api import db, app + @pytest.fixture def testing_client(scope='module'): - db.create_all() - account = Account('Test Account', '€') - db.session.add(account) - db.session.commit() + with app.app_context(): + db.create_all() + account = Account('Test Account', '€') + db.session.add(account) + db.session.commit() with app.test_client() as testing_client: yield testing_client - db.drop_all() \ No newline at end of file + with app.app_context(): + db.drop_all() \ No newline at end of file