From b64b31a952eb114a36e0bb6e3c34d0a7b6e678d2 Mon Sep 17 00:00:00 2001 From: Ivan Mikushin Date: Fri, 8 May 2015 14:25:11 +0500 Subject: [PATCH] use `with` for ssh subprocess --- tests/integration/rancherostest/test_system.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/integration/rancherostest/test_system.py b/tests/integration/rancherostest/test_system.py index 2b577265..69bf852b 100644 --- a/tests/integration/rancherostest/test_system.py +++ b/tests/integration/rancherostest/test_system.py @@ -32,17 +32,14 @@ def test_system_boot(qemu): @pytest.mark.timeout(40) def test_run_system_container(qemu): assert qemu.returncode is None + u.wait_for_ssh() ssh = subprocess.Popen( './scripts/ssh sudo system-docker run --rm busybox /bin/true', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) - try: - with ssh.stdout as f: - for ln in iter(f.readline, ''): - print(str.strip(ln)) - ssh.wait() - assert ssh.returncode == 0 - finally: - if ssh.returncode is None: - ssh.terminate() + with ssh, ssh.stdout as f: + for ln in iter(f.readline, ''): + print(str.strip(ln)) + + assert ssh.returncode == 0