Skip to content

Commit

Permalink
added sqlalchemy 1.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dwreeves committed Jul 22, 2021
1 parent e7047d1 commit 2ffc7a9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
python: [3.6.x, 3.7.x]
sqlalchemy: [1.2.*, 1.3.*]
sqlalchemy: [1.2.*, 1.3.*, 1.4.*]
services:
postgres:
image: postgres:11
Expand Down
2 changes: 1 addition & 1 deletion pytest_flask_sqlalchemy/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _engine(pytestconfig, request, _transaction, mocker):
# 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:
elif version.parse(sa.__version__) < version.parse('1.4'):
engine._contextual_connect.return_value = connection

# References to `Engine.dialect` should redirect to the Connection (this
Expand Down
12 changes: 5 additions & 7 deletions tests/_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import sqlalchemy as sa
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from pytest_postgresql.factories import (init_postgresql_database,
drop_postgresql_database)
from pytest_postgresql.janitor import DatabaseJanitor

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

init_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_pass)

@request.addfinalizer
def drop_database():
drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
janitor.init()
yield
janitor.drop()


@pytest.fixture(scope='session')
Expand Down
13 changes: 6 additions & 7 deletions tests/test_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def test_missing_db_fixture(testdir):
import sqlalchemy as sa
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from pytest_postgresql.factories import (init_postgresql_database,
drop_postgresql_database)
from pytest_postgresql.janitor import DatabaseJanitor
# Retrieve a database connection string from the shell environment
try:
Expand All @@ -102,11 +101,11 @@ def database(request):
pg_pass = DB_OPTS.get("password")
pg_db = DB_OPTS["database"]
init_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_pass)
janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
janitor.init()
yield
janitor.drop()
@request.addfinalizer
def drop_database():
drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, 9.6, pg_pass)
@pytest.fixture(scope='session')
Expand All @@ -130,7 +129,7 @@ def test_missing_db_fixture(db_session):
""")

result = testdir.runpytest()
result.assert_outcomes(error=1)
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines([
'*NotImplementedError: _db fixture not defined*'
])

0 comments on commit 2ffc7a9

Please sign in to comment.