From 237f690f8b5e976800676cb5c1c6c06fd30755b6 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 10 Feb 2019 14:31:38 +0100 Subject: [PATCH] --lsof: suppress stderr This can spam a lot of warnings (per invocation), e.g.: > lsof: WARNING: can't stat() nsfs file system /run/docker/netns/default Output information may be incomplete. Or from Travis/MacOS: > lsof: WARNING: can't stat() vmhgfs file system /Volumes/VMware Shared Folders > Output information may be incomplete. > assuming "dev=31000003" from mount table --- src/_pytest/pytester.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 9cadd2f9d..3ac2a9cfd 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -81,7 +81,11 @@ class LsofFdLeakChecker(object): def _exec_lsof(self): pid = os.getpid() - return subprocess.check_output(("lsof", "-Ffn0", "-p", str(pid))).decode() + # py3: use subprocess.DEVNULL directly. + with open(os.devnull, "wb") as devnull: + return subprocess.check_output( + ("lsof", "-Ffn0", "-p", str(pid)), stderr=devnull + ).decode() def _parse_lsof_output(self, out): def isopen(line):