def database(request): config = get_config(request) pg_host = config.get("host") pg_port = config.get("port") or os.environ.get("PGPORT", 5432) pg_user = config.get("user") pg_db = config.get("db", "tests") pg_version = config.get("version", 10.1) janitor = DatabaseJanitor(pg_user, pg_host, pg_port, pg_db, pg_version) # In case the database already exists, possibly due to an aborted test run, # attempt to drop it before creating try: janitor.drop() except InvalidCatalogName: # We can safely ignore this exception as that means there was # no leftover database pass # Create our Database. janitor.init() # Ensure our database gets deleted. @request.addfinalizer def drop_database(): janitor.drop() return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)
def database(request): config = get_config(request) pg_host = config.get("host") pg_port = config.get("port") or os.environ.get("PGPORT", 5432) pg_user = config.get("user") pg_db = config.get("db", "tests") pg_version = config.get("version", 10.1) # Create our Database. init_postgresql_database(pg_user, pg_host, pg_port, pg_db) # Ensure our database gets deleted. @request.addfinalizer def drop_database(): drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_version) return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)
def database(request): config = get_config(request) pg_host = config.get("host") pg_port = config.get("port") or os.environ.get("PGPORT", 5432) pg_user = config.get("user") pg_db = config.get("db", "tests") pg_version = config.get("version", 10.1) # In case the database already exists, possibly due to an aborted test run, # attempt to drop it before creating drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_version) # Create our Database. init_postgresql_database(pg_user, pg_host, pg_port, pg_db) # Ensure our database gets deleted. @request.addfinalizer def drop_database(): drop_postgresql_database(pg_user, pg_host, pg_port, pg_db, pg_version) return "postgresql://{}@{}:{}/{}".format(pg_user, pg_host, pg_port, pg_db)