@@ -27,11 +27,18 @@ def test_copy_to_with_psycopg2(self):
2727 """Test copy_to function with psycopg2."""
2828 # Mock the psycopg2 import to succeed and psycopg to fail
2929 with mock .patch .dict ("sys.modules" , {"psycopg" : None }):
30+ # Reload the module to ensure it uses the psycopg2 implementation
31+ import importlib
32+ import postgres_copy .psycopg_compat
33+
34+ importlib .reload (postgres_copy .psycopg_compat )
35+ from postgres_copy .psycopg_compat import copy_to as reloaded_copy_to
36+
3037 with mock .patch ("psycopg2.extensions.adapt" ) as mock_adapt :
3138 mock_adapt .return_value .getquoted .return_value = b"'test'"
3239
3340 # Call the function
34- copy_to (self .cursor , self .sql , (1 , 2 ), self .destination )
41+ reloaded_copy_to (self .cursor , self .sql , (1 , 2 ), self .destination )
3542
3643 # Check that the psycopg2 version was called with the right parameters
3744 self .cursor .copy_expert .assert_called_once ()
@@ -45,8 +52,15 @@ def test_copy_from_with_psycopg2(self):
4552 """Test copy_from function with psycopg2."""
4653 # Mock the psycopg2 import to succeed and psycopg to fail
4754 with mock .patch .dict ("sys.modules" , {"psycopg" : None }):
55+ # Reload the module to ensure it uses the psycopg2 implementation
56+ import importlib
57+ import postgres_copy .psycopg_compat
58+
59+ importlib .reload (postgres_copy .psycopg_compat )
60+ from postgres_copy .psycopg_compat import copy_from as reloaded_copy_from
61+
4862 # Call the function
49- copy_from (self .cursor , self .sql , self .source )
63+ reloaded_copy_from (self .cursor , self .sql , self .source )
5064
5165 # Check that the psycopg2 version was called with the right parameters
5266 self .cursor .copy_expert .assert_called_once ()
0 commit comments