Skip to content

Commit 2ffc7a9

Browse files
committed
added sqlalchemy 1.4 support
1 parent e7047d1 commit 2ffc7a9

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
python: [3.6.x, 3.7.x]
18-
sqlalchemy: [1.2.*, 1.3.*]
18+
sqlalchemy: [1.2.*, 1.3.*, 1.4.*]
1919
services:
2020
postgres:
2121
image: postgres:11

pytest_flask_sqlalchemy/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _engine(pytestconfig, request, _transaction, mocker):
102102
# https://docs.sqlalchemy.org/en/latest/changelog/migration_13.html
103103
if version.parse(sa.__version__) < version.parse('1.3'):
104104
engine.contextual_connect.return_value = connection
105-
else:
105+
elif version.parse(sa.__version__) < version.parse('1.4'):
106106
engine._contextual_connect.return_value = connection
107107

108108
# References to `Engine.dialect` should redirect to the Connection (this

tests/_conftest.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import sqlalchemy as sa
77
from flask import Flask
88
from flask_sqlalchemy import SQLAlchemy
9-
from pytest_postgresql.factories import (init_postgresql_database,
10-
drop_postgresql_database)
9+
from pytest_postgresql.janitor import DatabaseJanitor
1110

1211
# Retrieve a database connection string from the shell environment
1312
try:
@@ -33,11 +32,10 @@ def database(request):
3332
pg_pass = DB_OPTS.get("password")
3433
pg_db = DB_OPTS["database"]
3534

36-
init_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_pass)
37-
38-
@request.addfinalizer
39-
def drop_database():
40-
drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
35+
janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
36+
janitor.init()
37+
yield
38+
janitor.drop()
4139

4240

4341
@pytest.fixture(scope='session')

tests/test_configs.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def test_missing_db_fixture(testdir):
7575
import sqlalchemy as sa
7676
from flask import Flask
7777
from flask_sqlalchemy import SQLAlchemy
78-
from pytest_postgresql.factories import (init_postgresql_database,
79-
drop_postgresql_database)
78+
from pytest_postgresql.janitor import DatabaseJanitor
8079
8180
# Retrieve a database connection string from the shell environment
8281
try:
@@ -102,11 +101,11 @@ def database(request):
102101
pg_pass = DB_OPTS.get("password")
103102
pg_db = DB_OPTS["database"]
104103
105-
init_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_pass)
104+
janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
105+
janitor.init()
106+
yield
107+
janitor.drop()
106108
107-
@request.addfinalizer
108-
def drop_database():
109-
drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
110109
111110
112111
@pytest.fixture(scope='session')
@@ -130,7 +129,7 @@ def test_missing_db_fixture(db_session):
130129
""")
131130

132131
result = testdir.runpytest()
133-
result.assert_outcomes(error=1)
132+
result.assert_outcomes(errors=1)
134133
result.stdout.fnmatch_lines([
135134
'*NotImplementedError: _db fixture not defined*'
136135
])

0 commit comments

Comments
 (0)