From 8943f49c3e6064839bd1e3c2c73a750b2b476ae3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Wed, 15 Jul 2020 09:02:15 +0200
Subject: [PATCH 1/2] tests: Skip tests requiring specific data backends if not
 available

Skip tests that require a specific database backend if the respective
package is not available.  This is mostly intended to make it possible
to test flask-security on Python 3.9 since Pony does not support this
Python version but there is no harm in extending it to other backends.

Technically, Flask-SQLAlchemy is still required due to other tests.
---
 tests/conftest.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tests/conftest.py b/tests/conftest.py
index 3305d92..a48f480 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -218,6 +218,7 @@ def mongoengine_datastore(request, app, tmpdir, realdburl):
 
 
 def mongoengine_setup(request, app, tmpdir, realdburl):
+    pytest.importorskip('flask_mongoengine')
     from flask_mongoengine import MongoEngine
     from mongoengine.fields import (
         BooleanField,
@@ -282,6 +283,7 @@ def sqlalchemy_datastore(request, app, tmpdir, realdburl):
 
 
 def sqlalchemy_setup(request, app, tmpdir, realdburl):
+    pytest.importorskip('flask_sqlalchemy')
     from flask_sqlalchemy import SQLAlchemy
     from flask_security.models import fsqla_v2 as fsqla
 
@@ -326,6 +328,7 @@ def sqlalchemy_session_datastore(request, app, tmpdir, realdburl):
 
 
 def sqlalchemy_session_setup(request, app, tmpdir, realdburl):
+    pytest.importorskip('sqlalchemy')
     from sqlalchemy import create_engine
     from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
     from sqlalchemy.ext.declarative import declarative_base
@@ -426,6 +429,7 @@ def peewee_datastore(request, app, tmpdir, realdburl):
 
 
 def peewee_setup(request, app, tmpdir, realdburl):
+    pytest.importorskip('peewee')
     from peewee import (
         TextField,
         DateTimeField,
@@ -522,6 +526,7 @@ def pony_datastore(request, app, tmpdir, realdburl):
 
 def pony_setup(request, app, tmpdir, realdburl):
 
+    pytest.importorskip('pony')
     from pony.orm import Database, Optional, Required, Set
     from pony.orm.core import SetInstance
 
-- 
2.27.0

