From 2ffc7a9fa1849205ab559fa38254a46e171ef90d Mon Sep 17 00:00:00 2001 From: dwreeves Date: Wed, 21 Jul 2021 21:06:07 -0400 Subject: [PATCH] added sqlalchemy 1.4 support --- .github/workflows/main.yml | 2 +- pytest_flask_sqlalchemy/fixtures.py | 2 +- tests/_conftest.py | 12 +++++------- tests/test_configs.py | 13 ++++++------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 49e0325..8b6f3a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 diff --git a/pytest_flask_sqlalchemy/fixtures.py b/pytest_flask_sqlalchemy/fixtures.py index 0aee994..0396bd6 100644 --- a/pytest_flask_sqlalchemy/fixtures.py +++ b/pytest_flask_sqlalchemy/fixtures.py @@ -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 diff --git a/tests/_conftest.py b/tests/_conftest.py index d9fc9e6..5dfa0b8 100644 --- a/tests/_conftest.py +++ b/tests/_conftest.py @@ -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: @@ -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') diff --git a/tests/test_configs.py b/tests/test_configs.py index f30d9f4..759a650 100644 --- a/tests/test_configs.py +++ b/tests/test_configs.py @@ -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: @@ -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') @@ -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*' ])