diff mbox

[2/3] sandbox: tests - close stdout of p1

Message ID 1473950369-2547-2-git-send-email-plautrba@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Petr Lautrbach Sept. 15, 2016, 2:39 p.m. UTC
p1.stdout should be closed after it's connected to p2 according to
https://docs.python.org/3/library/subprocess.html#replacing-shell-pipeline

Fixes:
$ make PYTHON=python3 test
Verify that we can read file descriptors handed to sandbox ...
/usr/lib64/python3.5/unittest/case.py:638: ResourceWarning: unclosed
file <_io.BufferedReader name=4>
  testMethod()

Signed-off-by: Petr Lautrbach <plautrba@redhat.com>
---
 policycoreutils/sandbox/test_sandbox.py | 1 +
 1 file changed, 1 insertion(+)
diff mbox

Patch

diff --git a/policycoreutils/sandbox/test_sandbox.py b/policycoreutils/sandbox/test_sandbox.py
index d5368c2..98c04a7 100644
--- a/policycoreutils/sandbox/test_sandbox.py
+++ b/policycoreutils/sandbox/test_sandbox.py
@@ -28,6 +28,7 @@  class SandboxTests(unittest.TestCase):
         "Verify that we can read file descriptors handed to sandbox"
         p1 = Popen(['cat', '/etc/passwd'], stdout=PIPE)
         p2 = Popen([sys.executable, 'sandbox', 'grep', 'root'], stdin=p1.stdout, stdout=PIPE)
+        p1.stdout.close()
         out, err = p2.communicate()
         self.assertTrue(b'root' in out)