-
Notifications
You must be signed in to change notification settings - Fork 46
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
How to add a POSTGIS extension in a test database ? #24
Comments
installing PostGIS can be done in code. def tmp_postgis_db_(tmp_database):
"""
This fixture initialize the postgis extension in the temporary database
"""
# Creates a connection with autocommmit to save us from a few lines.
conn = connect(url=tmp_database.url, autocommit=True)
cur = conn.cursor()
cur.execute("CREATE EXTENSION postgis")
cur.close()
conn.close()
yield tmp_database |
Posting here for those coming from google. The code above works, but if you are using different database connection code, ensure you commit after the For example, using sqlalchemy: with db.engine.connect() as connection: # or however you do it
connection.execute(text("CREATE EXTENSION postgis;"))
connection.commit() # Very important! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am writing unit test for a function that makes a database connection and retrieves the SRID and Geometry type from a Postgres database ( having POSTGIS extension ) , How can i make an instance with a PostGIS extension?
The text was updated successfully, but these errors were encountered: