@@ -901,17 +901,34 @@ def test_empty_db_button_confirms_and_wipes(
901901 import psycopg
902902 from pathlib import Path
903903 repo = Path (__file__ ).resolve ().parents [3 ]
904+ # The fixture script expects a virgin database (plain CREATE EXTENSION
905+ # and CREATE SCHEMA provsql_test); the wipe reinstalled provsql and
906+ # leaves provsql_test (the active search_path schema) in place, so shed
907+ # both first. The database-level search_path that the original setup.sql
908+ # established (ALTER DATABASE ... SET search_path = provsql_test) must
909+ # also be reset: once provsql_test is dropped it points at a missing
910+ # schema, so the fresh sessions below would have no valid creation
911+ # target and setup.sql's CREATE EXTENSION would fail with "no schema
912+ # selected". setup.sql re-establishes the search_path itself.
904913 with psycopg .connect (test_dsn , autocommit = True ) as conn :
905- # The fixture script expects a virgin database (plain
906- # CREATE EXTENSION); the wipe reinstalled provsql, so shed
907- # it first.
908914 conn .execute ("DROP EXTENSION IF EXISTS provsql CASCADE" )
909915 conn .execute ("DROP SCHEMA IF EXISTS provsql CASCADE" )
910- for fname in ("setup.sql" , "add_provenance.sql" ):
911- sql_text = "\n " .join (
912- line for line in
913- (repo / "test" / "sql" / fname ).read_text ().splitlines ()
914- if not line .startswith ("\\ " ))
916+ conn .execute ("DROP SCHEMA IF EXISTS provsql_test CASCADE" )
917+ conn .execute (
918+ "DO $$ BEGIN EXECUTE format("
919+ "'ALTER DATABASE %I RESET search_path', current_database());"
920+ " END $$" )
921+ # Each file gets its own connection: setup.sql sets the search_path at
922+ # the database level (ALTER DATABASE), which only takes effect for
923+ # sessions opened afterwards, so add_provenance.sql must run in a fresh
924+ # one to resolve the provsql schema -- the same reason conftest seeds
925+ # per file.
926+ for fname in ("setup.sql" , "add_provenance.sql" ):
927+ sql_text = "\n " .join (
928+ line for line in
929+ (repo / "test" / "sql" / fname ).read_text ().splitlines ()
930+ if not line .startswith ("\\ " ))
931+ with psycopg .connect (test_dsn , autocommit = True ) as conn :
915932 conn .execute (sql_text )
916933 # The restore re-created the extension behind the server's back;
917934 # bounce its pool (same-database connection switch) so later
0 commit comments