From 437a19703d63801997f2ccece516a2790d438cee Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Fri, 9 Sep 2022 17:34:40 +0100 Subject: tests: Fix compatibility with PostgreSQL 14+ It seems postgres-client has changed the format of error messages. Previously we saw messages like: fatal: database "non_existent_database" does not exist These are now prefixed. For example: connection to server at "localhost" (::1), port 5432 failed: fatal: database "non_existent_database" does not exist You can see this in the docs. Compare the "Client Connection Problems" section for Postgres 13 [1] to Postgres 14 [2]. [1] https://www.postgresql.org/docs/13/server-start.html [2] https://www.postgresql.org/docs/14/server-start.html Change-Id: Id2c8eec202d128d142b8a8a8f904fcc14b6f52d7 Signed-off-by: Stephen Finucane Closes-bug: #1989208 --- oslo_db/tests/sqlalchemy/test_exc_filters.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py index 53789f5..7e03fce 100644 --- a/oslo_db/tests/sqlalchemy/test_exc_filters.py +++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py @@ -462,10 +462,20 @@ class TestNonExistentDatabasePostgreSQL( self.url ) self.assertEqual('non_existent_database', matched.database) - self.assertInnerException( - matched, + # NOTE(stephenfin): As above, we cannot use assertInnerException since + # the error messages vary depending on the version of PostgreSQL + self.assertIsInstance( + matched.inner_exception, sqlalchemy.exc.OperationalError, - 'fatal: database "non_existent_database" does not exist\n', + ) + # On Postgres 13: + # fatal: database "non_existent_database" does not exist + # On Postgres 14 or later: + # connection to server at "localhost" (::1), port 5432 failed: fatal: + # database "non_existent_database" does not exist + self.assertIn( + 'fatal: database "non_existent_database" does not exist', + str(matched.inner_exception).lower(), ) -- cgit v1.2.1