From 9da2210f121085e998dc7cedb783bc4568390b92 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 8 Dec 2022 14:31:35 +0100 Subject: [PATCH] Avoided direct mocking of psycopg2.__version__ in test_correct_extraction_psycopg2_version(). --- tests/backends/postgresql/tests.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/backends/postgresql/tests.py b/tests/backends/postgresql/tests.py index f056162454..d375bd2b8c 100644 --- a/tests/backends/postgresql/tests.py +++ b/tests/backends/postgresql/tests.py @@ -291,12 +291,14 @@ class Tests(TestCase): "::citext", do.lookup_cast(lookup, internal_type=field_type) ) - def test_correct_extraction_psycopg2_version(self): - from django.db.backends.postgresql.base import psycopg2_version + def test_correct_extraction_psycopg_version(self): + from django.db.backends.postgresql.base import Database, psycopg2_version - with mock.patch("psycopg2.__version__", "4.2.1 (dt dec pq3 ext lo64)"): + with mock.patch.object(Database, "__version__", "4.2.1 (dt dec pq3 ext lo64)"): self.assertEqual(psycopg2_version(), (4, 2, 1)) - with mock.patch("psycopg2.__version__", "4.2b0.dev1 (dt dec pq3 ext lo64)"): + with mock.patch.object( + Database, "__version__", "4.2b0.dev1 (dt dec pq3 ext lo64)" + ): self.assertEqual(psycopg2_version(), (4, 2)) @override_settings(DEBUG=True)