@@ -227,18 +227,21 @@ def test_connect_with_rsa_ssh_key_wrong_password(self):
227227 ('somehost' , {'ssh_key' : 'testkey' , 'ssh_key_password' : 'testpass' }),
228228 )), Config ())
229229
230+ fake_fail_from_private_key_file = MagicMock ()
231+ fake_fail_from_private_key_file .side_effect = make_raise_exception_function (SSHException )
232+
230233 with patch (
231234 'pyinfra.api.connectors.ssh.path.isfile' ,
232235 lambda * args , ** kwargs : True ,
233236 ), patch (
234237 'pyinfra.api.connectors.ssh.DSSKey.from_private_key_file' ,
235- make_raise_exception_function ( SSHException ) ,
238+ fake_fail_from_private_key_file ,
236239 ), patch (
237240 'pyinfra.api.connectors.ssh.ECDSAKey.from_private_key_file' ,
238- make_raise_exception_function ( SSHException ) ,
241+ fake_fail_from_private_key_file ,
239242 ), patch (
240243 'pyinfra.api.connectors.ssh.Ed25519Key.from_private_key_file' ,
241- make_raise_exception_function ( SSHException ) ,
244+ fake_fail_from_private_key_file ,
242245 ), patch (
243246 'pyinfra.api.connectors.ssh.RSAKey.from_private_key_file' ,
244247 ) as fake_key_open :
@@ -253,13 +256,13 @@ def fake_key_open_fail(*args, **kwargs):
253256 fake_key = MagicMock ()
254257 fake_key_open .return_value = fake_key
255258
256- state .deploy_dir = '/'
257-
258259 with self .assertRaises (PyinfraError ) as e :
259260 connect_all (state )
260261
261262 assert e .exception .args [0 ] == 'Invalid private key file: testkey'
262263
264+ assert fake_fail_from_private_key_file .call_count == 3
265+
263266 def test_connect_with_dss_ssh_key (self ):
264267 state = State (make_inventory (hosts = (
265268 ('somehost' , {'ssh_key' : 'testkey' }),
0 commit comments