Skip to content

Commit 8709449

Browse files
authored
Merge pull request #15 from jeancochrane/jfc/bugfix/sqlalchemy-1.3-support
Support SQLAlchemy 1.3 deprecated threadlocal strategy
2 parents e9ddaab + a10b23c commit 8709449

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

.travis.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@ branches:
55

66
language: python
77
python:
8-
- '3.4'
9-
- '3.5'
108
- '3.6'
9+
- '3.5'
10+
- '3.4'
1111

1212
env:
13-
- TEST_DATABASE_URL=postgresql://postgres@localhost:5432/pytest_test
13+
global:
14+
- TEST_DATABASE_URL=postgresql://postgres@localhost:5432/pytest_test
15+
16+
matrix:
17+
include:
18+
- env: SA_VERSION=1.3.*
19+
- env: SA_VERSION=1.2.*
1420

1521
addons:
1622
postgresql: '9.6'
1723

1824
install:
1925
- pip install --upgrade pip
2026
- pip install -e .[tests]
27+
- if ![ -z "$SA_VERSION" ]; then pip install --upgrade sqlalchemy=="${SA_VERSION}"; fi
2128

2229
script: pytest
2330

CHANGELOG.md

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

8+
## Unreleased
9+
10+
- Support SQLAlchemy 1.3 by adjusting the mock for threadlocal engine strategy [\#15](https://github.com/jeancochrane/pytest-flask-sqlalchemy/pull/15)
11+
812
## [1.0.1](https://github.com/jeancochrane/pytest-flask-sqlalchemy/releases/tag/v1.0.1) (2019-03-02)
913

1014
### Changed

pytest_flask_sqlalchemy/fixtures.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
import sqlalchemy as sa
6+
from packaging import version
67

78

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

9798
engine.connect.return_value = connection
98-
engine.contextual_connect.return_value = connection
99+
100+
# Threadlocal engine strategies were deprecated in SQLAlchemy 1.3, which
101+
# resulted in contextual_connect becoming a private method. See:
102+
# https://docs.sqlalchemy.org/en/latest/changelog/migration_13.html
103+
if version.parse(sa.__version__) < version.parse('1.3'):
104+
engine.contextual_connect.return_value = connection
105+
else:
106+
engine._contextual_connect.return_value = connection
99107

100108
# References to `Engine.dialect` should redirect to the Connection (this
101109
# is primarily useful for the `autoload` flag in SQLAlchemy, which references

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ def readme():
1919
install_requires=['pytest>=3.2.1',
2020
'pytest-mock>=1.6.2',
2121
'SQLAlchemy>=1.2.2',
22-
'Flask-SQLAlchemy>=2.3'],
22+
'Flask-SQLAlchemy>=2.3',
23+
'packaging>=14.1'],
2324
extras_require={'tests': ['pytest-postgresql']},
2425
classifiers=[
2526
'Development Status :: 4 - Beta',

0 commit comments

Comments
 (0)