Skip to content

Commit 3ae8173

Browse files
committed
tests: fix missing logs & fixup ssh connector test
1 parent dc3e312 commit 3ae8173

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tests/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import gevent.hub
55

66
import pyinfra_cli # noqa: F401
7+
from pyinfra import logger
78

89
logging.basicConfig(level=logging.DEBUG)
9-
logger = logging.getLogger("pyinfra.tests")
10+
logger.setLevel(logging.DEBUG)
1011

1112
# Don't print out exceptions inside greenlets (because here we expect them!)
1213
gevent.hub.Hub.NOT_ERROR = (Exception,)

tests/test_connectors/test_ssh.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from paramiko import AuthenticationException, PasswordRequiredException, SSHException
77

88
import pyinfra
9-
from pyinfra.api import Config, MaskString, State, StringCommand
9+
from pyinfra.api import Config, Host, MaskString, State, StringCommand
1010
from pyinfra.api.connect import connect_all
1111
from pyinfra.api.exceptions import ConnectError, PyinfraError
1212

@@ -850,11 +850,13 @@ def test_put_file_su_user_fail_acl(self, fake_sftp_client, fake_ssh_client):
850850
def test_put_file_su_user_fail_copy(self, fake_sftp_client, fake_ssh_client):
851851
inventory = make_inventory(hosts=("anotherhost",))
852852
State(inventory, Config())
853+
853854
host = inventory.get_host("anotherhost")
855+
assert isinstance(host, Host)
854856
host.connect()
855857

856858
stdout_mock = mock.MagicMock()
857-
exit_codes = [0, 1]
859+
exit_codes = [0, 0, 1]
858860
stdout_mock.channel.recv_exit_status.side_effect = lambda: exit_codes.pop(0)
859861
fake_ssh_client().exec_command.return_value = (
860862
mock.MagicMock(),
@@ -865,7 +867,7 @@ def test_put_file_su_user_fail_copy(self, fake_sftp_client, fake_ssh_client):
865867
fake_open = mock.mock_open(read_data="test!")
866868
with mock.patch("pyinfra.api.util.open", fake_open, create=True):
867869
status = host.put_file(
868-
"not-a-file",
870+
fake_open(),
869871
"not-another-file",
870872
print_output=True,
871873
_su_user="centos",
@@ -881,7 +883,7 @@ def test_put_file_su_user_fail_copy(self, fake_sftp_client, fake_ssh_client):
881883
get_pty=False,
882884
)
883885

884-
fake_ssh_client().exec_command.assert_called_with(
886+
fake_ssh_client().exec_command.assert_any_call(
885887
(
886888
"su centos -c 'sh -c '\"'\"'cp "
887889
"/tmp/pyinfra-43db9984686317089fefcf2e38de527e4cb44487 "

0 commit comments

Comments
 (0)