pytest-flask example with SQLAlchemy
@northernSage ya está trabajando en esto.
Desde el 25/3/2021.
Evaluación
Este issue todavía no se ha evaluado.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 499
- Forks
- 93
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytest-dev/pytest-flask
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
pytest-dev/pytest-flask#190 · 1 comentario · 1 reacción ·
-
Incompatibility with flask-babelAbiertobug
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
pytest-dev/pytest-flask#187 · 7 comentarios ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
pytest-dev/pytest-flask#175 · 3 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
pytest-dev/pytest-flask#163 · 1 comentario · 1 reacción ·
-
feature request
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
pytest-dev/pytest-flask#153 · 1 comentario ·
Todos los issues de pytest-dev/pytest-flask
Issues similares
-
good first issue tools
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Commits pushed after #1095 merged did not land (ahmi/unified-nova-mcp-review-e095 @ 80fa23a)Abiertobug deferred domain:ci P1
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
get_page_thumbnail modifies cached page images, affecting later thumbnails and picture exportsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
docling-project/docling-mcp#147 ·
-
issue: A pipe model's Valves button ignores the Allow Chat Valves permissionPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug confirmed issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
open-webui/open-webui#32771 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Scheduled Security Scan is failing on mainPosiblemente ocupada @pkupt la tomó hoy. Abiertosecurity-scan-failure
Dificultad 1/5 1-3 horas Aptitud para principiantes 74/100
semantica-agi/semantica#2045 ·
Los mantenedores suelen responder en 2 días