mirror of
https://github.com/simple-login/app.git
synced 2025-02-23 23:34:05 +08:00
handle case pg_trgm can't be dropped when running test
This commit is contained in:
parent
153831ed1a
commit
0aa3dff38b
1 changed files with 11 additions and 2 deletions
|
@ -2,10 +2,14 @@ import os
|
|||
|
||||
# use the tests/test.env config fle
|
||||
# flake8: noqa: E402
|
||||
import sqlalchemy
|
||||
|
||||
os.environ["CONFIG"] = os.path.abspath(
|
||||
os.path.join(os.path.dirname(os.path.dirname(__file__)), "tests/test.env")
|
||||
)
|
||||
|
||||
from psycopg2 import errors
|
||||
from psycopg2.errorcodes import DEPENDENT_OBJECTS_STILL_EXIST
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -21,8 +25,13 @@ app.config["SERVER_NAME"] = "sl.test"
|
|||
with app.app_context():
|
||||
# enable pg_trgm extension
|
||||
with db.engine.connect() as conn:
|
||||
conn.execute("DROP EXTENSION if exists pg_trgm")
|
||||
conn.execute("CREATE EXTENSION pg_trgm")
|
||||
try:
|
||||
conn.execute("DROP EXTENSION if exists pg_trgm")
|
||||
conn.execute("CREATE EXTENSION pg_trgm")
|
||||
except sqlalchemy.exc.InternalError as e:
|
||||
if isinstance(e.orig, errors.lookup(DEPENDENT_OBJECTS_STILL_EXIST)):
|
||||
print(">>> pg_trgm can't be dropped, ignore")
|
||||
conn.execute("Rollback")
|
||||
|
||||
db.create_all()
|
||||
|
||||
|
|
Loading…
Reference in a new issue