Fix #23807 - Ignore psycopg2 version part if it is non-digit

This looks good, but I think we need to "cleanup" after the test and restore `Database.__version__` to its original value. I am thinking we can use `mock.patch` for this once https://github.com/django/django/pull/3649 is merged. The following worked for me after I rebased your branch on the mock PR:
```diff
diff --git a/tests/backends/tests.py b/tests/backends/tests.py
index 2d6fba6..cf3e22a 100644
--- a/tests/backends/tests.py
+++ b/tests/backends/tests.py
@@ -22,7 +22,7 @@ from django.db.backends.utils import format_number, CursorWrapper
 from django.db.models import Sum, Avg, Variance, StdDev
 from django.db.models.sql.constants import CURSOR
 from django.db.utils import ConnectionHandler
-from django.test import (TestCase, TransactionTestCase, override_settings,
+from django.test import (TestCase, TransactionTestCase, mock, override_settings,
     skipUnlessDBFeature, skipIfDBFeature)
 from django.test.utils import str_prefix, IgnoreAllDeprecationWarningsMixin
 from django.utils import six
@@ -247,15 +247,15 @@ class PostgreSQLTests(TestCase):
             self.assertIn('::text', do.lookup_cast(lookup))
 
     def test_correct_extraction_psycopg2_version(self):
-        from django.db.backends.postgresql_psycopg2.base import Database, DatabaseWrapper
+        from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper
 
-        only_digit_version = '2.6.9'
-        Database.__version__ = only_digit_version
-        self.assertEqual(DatabaseWrapper.psycopg2_version.__get__(self), (2, 6, 9))
+        version_path = 'django.db.backends.postgresql_psycopg2.base.Database.__version__'
 
-        version_with_non_digits = '2.5.dev0'
-        Database.__version__ = version_with_non_digits
-        self.assertEqual(DatabaseWrapper.psycopg2_version.__get__(self), (2, 5))
+        with mock.patch(version_path,  '2.6.9'):
+            self.assertEqual(DatabaseWrapper.psycopg2_version.__get__(self), (2, 6, 9))
+
+        with mock.patch(version_path, '2.5.dev0'):
+            self.assertEqual(DatabaseWrapper.psycopg2_version.__get__(self), (2, 5))
 
 
 class DateQuotingTest(TestCase):
```