mirror of
https://github.com/simple-login/app.git
synced 2025-02-24 07:43:54 +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
|
# use the tests/test.env config fle
|
||||||
# flake8: noqa: E402
|
# flake8: noqa: E402
|
||||||
|
import sqlalchemy
|
||||||
|
|
||||||
os.environ["CONFIG"] = os.path.abspath(
|
os.environ["CONFIG"] = os.path.abspath(
|
||||||
os.path.join(os.path.dirname(os.path.dirname(__file__)), "tests/test.env")
|
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
|
import pytest
|
||||||
|
|
||||||
|
@ -21,8 +25,13 @@ app.config["SERVER_NAME"] = "sl.test"
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
# enable pg_trgm extension
|
# enable pg_trgm extension
|
||||||
with db.engine.connect() as conn:
|
with db.engine.connect() as conn:
|
||||||
conn.execute("DROP EXTENSION if exists pg_trgm")
|
try:
|
||||||
conn.execute("CREATE EXTENSION pg_trgm")
|
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()
|
db.create_all()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue