diff --git a/tests/integration/postgres/conftest.py b/tests/integration/postgres/conftest.py index 850260f..49155d1 100644 --- a/tests/integration/postgres/conftest.py +++ b/tests/integration/postgres/conftest.py @@ -36,7 +36,15 @@ def postgres_container() -> Iterator[PostgresContainer]: @pytest.fixture(scope="session") def postgres_url(postgres_container: PostgresContainer) -> str: - return postgres_container.get_connection_url() + """The container's URL, pinned to IPv4. + + Testcontainers reports the host as `localhost`, which resolves to `::1` + before `127.0.0.1`. Docker publishes the mapped port on IPv4 only, and the + IPv6 SYN is dropped rather than refused, so asyncpg blocks on the first + address until its connect timeout instead of falling back to the second -- + the connection does not fail, it hangs. + """ + return postgres_container.get_connection_url().replace("@localhost:", "@127.0.0.1:") @pytest.fixture(scope="session")