pytest-flask example with SQLAlchemy
@northernSage đang làm issue này rồi.
Từ ngày 25/3/2021.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Hi, there
Could you include a SQLAlchemy example in the documentation? I'm using the following code but it doesn't work:
import pytest
from projeto import create_app, db as _db
@pytest.fixture(scope='session')
def app():
app = create_app('testing')
return app
@pytest.fixture(scope='session')
def db(app, request):
_db.app = app
_db.create_all()
yield _db
_db.drop_all()
@pytest.yield_fixture(scope='function')
def session(db):
connection = db.engine.connect()
transaction = connection.begin()
options = dict(bind=connection)
session = db.create_scoped_session(options=options)
db.session = session
yield session
transaction.rollback()
connection.close()
session.remove()
This is the error that I get:
app = <Flask 'projeto'>, request = <SubRequest 'db' for <Function 'test_login_page'>>
@pytest.fixture(scope='session')
def db(app, request):
_db.app = app
_db.create_all()
yield _db
> _db.drop_all()
conftest.py:14:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:1015: in drop_all
self._execute_for_all_tables(app, bind, 'drop_all')
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:999: in _execute_for_all_tables
op(bind=self.get_engine(app, bind), **extra)
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:941: in get_engine
return connector.get_engine()
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:533: in get_engine
uri = self.get_uri()
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/flask_sqlalchemy/__init__.py:524: in get_uri
return self._app.config['SQLALCHEMY_DATABASE_URI']
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/werkzeug/local.py:347: in __getattr__
return getattr(self._get_current_object(), name)
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/werkzeug/local.py:306: in _get_current_object
return self.__local()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def _find_app():
top = _app_ctx_stack.top
if top is None:
> raise RuntimeError(_app_ctx_err_msg)
E RuntimeError: Working outside of application context.
E
E This typically means that you attempted to use functionality that needed
E to interface with the current application object in a way. To solve
E this set up an application context with app.app_context(). See the
E documentation for more information.
/home/andref/.virtualenvs/projeto/lib/python3.5/site-packages/flask/globals.py:51: RuntimeError
- Ngôn ngữ chính
- Python
- Star
- 499
- Fork
- 93
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytest-dev/pytest-flask
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
pytest-dev/pytest-flask#190 · 1 bình luận · 1 reaction ·
-
Incompatibility with flask-babelĐang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
pytest-dev/pytest-flask#187 · 7 bình luận ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
pytest-dev/pytest-flask#175 · 3 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
pytest-dev/pytest-flask#163 · 1 bình luận · 1 reaction ·
-
feature request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
pytest-dev/pytest-flask#153 · 1 bình luận ·
Tất cả issue của pytest-dev/pytest-flask
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ianktoo/project-monitor#14 ·
-
A wrong descriptor checksum is refused with the right one, also for an xprv or WIF descriptorĐang mởsecurity
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
btclib-org/btclib-wallet#478 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
btclib-org/btclib#2727 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue lead variant:container
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
radialmonster/orf-cleanroom#10 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
gdsa opencode: keep-alive cleanup trap fails with 'keepalive_pid: unbound variable'Có thể đã có người làm @darribas đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100