From f018c5ca5e1aaca2f5c5bc9fca7dd4237401cc83 Mon Sep 17 00:00:00 2001 From: "wu.zhihui" Date: Mon, 13 Mar 2017 11:13:14 +0800 Subject: optimize console info - use QtipLogger instead of print - delete useless print Change-Id: I1e08382a5d78ce53cf455496363bce3762b81dd2 Signed-off-by: wu.zhihui (cherry picked from commit 3391a3c6ab4f6b33e2f6d74e858a7bad573695b1) --- tests/unit/util/env_test.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) (limited to 'tests') diff --git a/tests/unit/util/env_test.py b/tests/unit/util/env_test.py index 62d12a13..793d1e4e 100644 --- a/tests/unit/util/env_test.py +++ b/tests/unit/util/env_test.py @@ -72,12 +72,10 @@ def test_init(ansible_envsetup): assert ansible_envsetup.host_ip_list == [] -def test_setup_exception(capsys, mocker, ansible_envsetup, hostfile): +def test_setup_exception(mocker, ansible_envsetup, hostfile): with mock.patch.object(AnsibleEnvSetup, 'check_hostfile', side_effect=RuntimeError()): mock_os = mocker.patch('sys.exit') ansible_envsetup.setup({'hostfile': str(hostfile)}) - out, error = capsys.readouterr() - assert out == '\n' assert mock_os.call_count == 1 @@ -178,21 +176,17 @@ def test_pass_keypair_to_remote_failed(mocker, ansible_envsetup): assert "Failed on passing keypair to remote." in str(excinfo.value) -def test_pass_keypair(monkeypatch, capsys, mocker, ansible_envsetup): +def test_pass_keypair(monkeypatch, mocker, ansible_envsetup): monkeypatch.setattr(time, 'sleep', lambda s: None) mock_os = mocker.patch('os.system') ansible_envsetup._pass_keypair('10.20.0.3', str(private_key)) assert mock_os.call_count == 2 - out, error = capsys.readouterr() - assert "Pass keypair to remote hosts 10.20.0.3 successfully" in out -def test_pass_keypair_exception(capsys, ansible_envsetup): +def test_pass_keypair_exception(ansible_envsetup): with mock.patch('os.system', side_effect=Exception()) as mock_os: result = ansible_envsetup._pass_keypair('10.20.0.3', str(private_key)) assert result is False - out, error = capsys.readouterr() - assert out == '\n' assert mock_os.call_count == 1 @@ -304,20 +298,10 @@ def test_ssh_is_ok(mocker, ansible_envsetup, private_key, stderrinfo, expected): test_ssh_client.exec_command.assert_called_with('uname') -@pytest.mark.parametrize("attempts, expected", [ - (1, - 'Check hosts 10.20.0.3 ssh connectivity...\n1 times ssh test......failed.\n'), - (2, - 'Check hosts 10.20.0.3 ssh connectivity...\n' - '1 times ssh test......failed.\n' - '2 times ssh test......failed.\n') -]) -def test_ssh_exception(capsys, monkeypatch, mocker, ansible_envsetup, attempts, expected): +def test_ssh_exception(monkeypatch, mocker, ansible_envsetup): monkeypatch.setattr(time, 'sleep', lambda s: None) mock_sshclient = mocker.patch('paramiko.SSHClient') test_ssh_client = mock_sshclient.return_value test_ssh_client.exec_command.side_effect = socket.error() - result = ansible_envsetup._ssh_is_ok('10.20.0.3', str(private_key), attempts=attempts) - out, error = capsys.readouterr() - assert expected == out + result = ansible_envsetup._ssh_is_ok('10.20.0.3', str(private_key), attempts=1) assert result is False -- cgit 1.2.3-korg