@@ -81,10 +81,7 @@ def test_connect_exceptions(self, fake_key_open):
8181 ('somehost' , {'ssh_key' : 'testkey' }),
8282 )), Config ())
8383
84- def raise_exception (* args , ** kwargs ):
85- raise exception_class
86-
87- self .fake_connect_mock .side_effect = raise_exception
84+ self .fake_connect_mock .side_effect = make_raise_exception_function (exception_class )
8885
8986 with self .assertRaises (PyinfraError ):
9087 connect_all (state )
@@ -204,10 +201,7 @@ def test_connect_with_rsa_ssh_key_missing_password(self):
204201 'pyinfra.api.connectors.ssh.RSAKey.from_private_key_file' ,
205202 ) as fake_key_open :
206203
207- def fake_key_open_fail (* args , ** kwargs ):
208- raise PasswordRequiredException
209-
210- fake_key_open .side_effect = fake_key_open_fail
204+ fake_key_open .side_effect = make_raise_exception_function (PasswordRequiredException )
211205
212206 fake_key = MagicMock ()
213207 fake_key_open .return_value = fake_key
@@ -272,10 +266,7 @@ def test_connect_with_dss_ssh_key(self):
272266 patch ('pyinfra.api.connectors.ssh.RSAKey.from_private_key_file' ) as fake_rsa_key_open , \
273267 patch ('pyinfra.api.connectors.ssh.DSSKey.from_private_key_file' ) as fake_key_open : # noqa
274268
275- def fake_rsa_key_open_fail (* args , ** kwargs ):
276- raise SSHException
277-
278- fake_rsa_key_open .side_effect = fake_rsa_key_open_fail
269+ fake_rsa_key_open .side_effect = make_raise_exception_function (SSHException )
279270
280271 fake_key = MagicMock ()
281272 fake_key_open .return_value = fake_key
@@ -726,10 +717,7 @@ def test_get_sftp_fail(self, fake_sftp_client, fake_ssh_client):
726717 host = inventory .get_host ('anotherhost' )
727718 host .connect ()
728719
729- def raise_exception (* args , ** kwargs ):
730- raise SSHException ()
731-
732- fake_sftp_client .from_transport .side_effect = raise_exception
720+ fake_sftp_client .from_transport .side_effect = make_raise_exception_function (SSHException )
733721
734722 fake_open = mock_open (read_data = 'test!' )
735723 with patch ('pyinfra.api.util.open' , fake_open , create = True ):
0 commit comments