Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLAlchemy 1.4 support #51

Merged
merged 1 commit into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*'
])