Skip to content

Commit

Permalink
Merge pull request #15 from jeancochrane/jfc/bugfix/sqlalchemy-1.3-su…
Browse files Browse the repository at this point in the history
…pport

Support SQLAlchemy 1.3 deprecated threadlocal strategy
  • Loading branch information
jeancochrane authored Apr 4, 2019
2 parents e9ddaab + a10b23c commit 8709449
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
13 changes: 10 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ branches:

language: python
python:
- '3.4'
- '3.5'
- '3.6'
- '3.5'
- '3.4'

env:
- TEST_DATABASE_URL=postgresql://postgres@localhost:5432/pytest_test
global:
- TEST_DATABASE_URL=postgresql://postgres@localhost:5432/pytest_test

matrix:
include:
- env: SA_VERSION=1.3.*
- env: SA_VERSION=1.2.*

addons:
postgresql: '9.6'

install:
- pip install --upgrade pip
- pip install -e .[tests]
- if ![ -z "$SA_VERSION" ]; then pip install --upgrade sqlalchemy=="${SA_VERSION}"; fi

script: pytest

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- Support SQLAlchemy 1.3 by adjusting the mock for threadlocal engine strategy [\#15](https://github.com/jeancochrane/pytest-flask-sqlalchemy/pull/15)

## [1.0.1](https://github.com/jeancochrane/pytest-flask-sqlalchemy/releases/tag/v1.0.1) (2019-03-02)

### Changed
Expand Down
10 changes: 9 additions & 1 deletion pytest_flask_sqlalchemy/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
import sqlalchemy as sa
from packaging import version


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -95,7 +96,14 @@ def _engine(pytestconfig, request, _transaction, mocker):
engine = mocker.MagicMock(spec=sa.engine.Engine)

engine.connect.return_value = connection
engine.contextual_connect.return_value = connection

# Threadlocal engine strategies were deprecated in SQLAlchemy 1.3, which
# resulted in contextual_connect becoming a private method. See:
# https://docs.sqlalchemy.org/en/latest/changelog/migration_13.html
if version.parse(sa.__version__) < version.parse('1.3'):
engine.contextual_connect.return_value = connection
else:
engine._contextual_connect.return_value = connection

# References to `Engine.dialect` should redirect to the Connection (this
# is primarily useful for the `autoload` flag in SQLAlchemy, which references
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def readme():
install_requires=['pytest>=3.2.1',
'pytest-mock>=1.6.2',
'SQLAlchemy>=1.2.2',
'Flask-SQLAlchemy>=2.3'],
'Flask-SQLAlchemy>=2.3',
'packaging>=14.1'],
extras_require={'tests': ['pytest-postgresql']},
classifiers=[
'Development Status :: 4 - Beta',
Expand Down

0 comments on commit 8709449

Please sign in to comment.