diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-10-24 21:12:37 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-10-24 21:12:37 +0200 |
commit | 82c0876f1bec1e1b758bdcbbafb88f0c02cb3751 (patch) | |
tree | 583e6b5b7b1f7eb679812d9fbc28387a05cdfe88 | |
parent | 9d2987f5847256c713d5717dc630c471d4acb87a (diff) | |
download | psutil-82c0876f1bec1e1b758bdcbbafb88f0c02cb3751.tar.gz |
fix Popen test which is occasionally failing
-rwxr-xr-x | psutil/tests/test_process.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 33f8450c..6e4073d1 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -1435,14 +1435,31 @@ class TestProcess(unittest.TestCase): self.assertTrue(psutil.pid_exists(0)) def test_Popen(self): - with psutil.Popen([PYTHON, "-V"], stdout=subprocess.PIPE, - stderr=subprocess.PIPE) as proc: + # XXX this test causes a ResourceWarning on Python 3 because + # psutil.__subproc instance doesn't get propertly freed. + # Not sure what to do though. + cmd = [PYTHON, "-c", "import time; time.sleep(60);"] + proc = psutil.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + try: proc.name() proc.cpu_times() proc.stdin self.assertTrue(dir(proc)) self.assertRaises(AttributeError, getattr, proc, 'foo') - proc.wait() + finally: + proc.kill() + proc.wait() + + def test_Popen_ctx_manager(self): + with psutil.Popen([PYTHON, "-V"], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + stdin=subprocess.PIPE) as proc: + pass + assert proc.stdout.closed + assert proc.stderr.closed + assert proc.stdin.closed @unittest.skipUnless(hasattr(psutil.Process, "environ"), "platform not supported") |