diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1aec67e..4ecd7c4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,6 +16,8 @@ jobs: matrix: python: [3.7.x, 3.8.x, 3.9.x, 3.10.x] sqlalchemy: [1.2.*, 1.3.*, 1.4.*] + flask_sqlalchemy: [2.*] + # flask_sqlalchemy: [2.*, 3.*] services: postgres: image: postgres:11 @@ -36,7 +38,9 @@ jobs: pip install --upgrade pip pip install -e .[tests] pip install --upgrade sqlalchemy=="${SQLALCHEMY_VERSION}" + pip install --upgrade flask-sqlalchemy=="${FLASK_SQLALCHEMY_VERSION}" pytest env: TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/pytest_test SQLALCHEMY_VERSION: ${{ matrix.sqlalchemy }} + FLASK_SQLALCHEMY_VERSION: ${{ matrix.flask_sqlalchemy }} diff --git a/pytest_flask_sqlalchemy/fixtures.py b/pytest_flask_sqlalchemy/fixtures.py index 0396bd6..86a1003 100644 --- a/pytest_flask_sqlalchemy/fixtures.py +++ b/pytest_flask_sqlalchemy/fixtures.py @@ -35,7 +35,13 @@ def _transaction(request, _db, mocker): # when specifying a `bind` option, or else Flask-SQLAlchemy won't scope # the connection properly options = dict(bind=connection, binds={}) - session = _db.create_scoped_session(options=options) + try: + create_scoped_session = _db.create_scoped_session + except AttributeError: + # For Flask-SQLAlchemy version > 3.0 + create_scoped_session = _db._make_scoped_session + + session = create_scoped_session(options=options) # Make sure the session, connection, and transaction can't be closed by accident in # the codebase