Skip to content

Commit

Permalink
#1058: ignore stderr from procsmem.py
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed May 10, 2017
1 parent 4823c3a commit a250dbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 7 additions & 4 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,19 @@ def pyrun(src, **kwds):


@_cleanup_on_err
def sh(cmd):
def sh(cmd, **kwds):
"""run cmd in a subprocess and return its output.
raises RuntimeError on error.
"""
shell = True if isinstance(cmd, (str, unicode)) else False
# Prevents subprocess to open error dialogs in case of error.
flags = 0x8000000 if WINDOWS and shell else 0
p = subprocess.Popen(cmd, shell=shell, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, universal_newlines=True,
creationflags=flags)
kwds.setdefault("shell", shell)
kwds.setdefault("stdout", subprocess.PIPE)
kwds.setdefault("stderr", subprocess.PIPE)
kwds.setdefault("universal_newlines", True)
kwds.setdefault("creationflags", flags)
p = subprocess.Popen(cmd, **kwds)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise RuntimeError(stderr)
Expand Down
7 changes: 4 additions & 3 deletions psutil/tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from psutil.tests import chdir
from psutil.tests import create_proc_children_pair
from psutil.tests import create_sockets
from psutil.tests import DEVNULL
from psutil.tests import get_free_port
from psutil.tests import get_test_subprocess
from psutil.tests import HAS_BATTERY
Expand Down Expand Up @@ -631,12 +632,12 @@ class TestScripts(unittest.TestCase):
"""Tests for scripts in the "scripts" directory."""

@staticmethod
def assert_stdout(exe, args=None):
def assert_stdout(exe, args=None, **kwds):
exe = '"%s"' % os.path.join(SCRIPTS_DIR, exe)
if args:
exe = exe + ' ' + args
try:
out = sh(sys.executable + ' ' + exe).strip()
out = sh(sys.executable + ' ' + exe, **kwds).strip()
except RuntimeError as err:
if 'AccessDenied' in str(err):
return str(err)
Expand Down Expand Up @@ -712,7 +713,7 @@ def test_pmap(self):

@unittest.skipIf(not HAS_MEMORY_FULL_INFO, "not supported")
def test_procsmem(self):
self.assert_stdout('procsmem.py')
self.assert_stdout('procsmem.py', stderr=DEVNULL)

def test_killall(self):
self.assert_syntax('killall.py')
Expand Down
3 changes: 2 additions & 1 deletion psutil/tests/test_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def call(p, attr):
p = psutil.Process(os.getpid())
failures = []
ignored_names = ['terminate', 'kill', 'suspend', 'resume', 'nice',
'send_signal', 'wait', 'children', 'as_dict']
'send_signal', 'wait', 'children', 'as_dict',
'memory_info_ex']
if LINUX and get_kernel_version() < (2, 6, 36):
ignored_names.append('rlimit')
if LINUX and get_kernel_version() < (2, 6, 23):
Expand Down

0 comments on commit a250dbc

Please sign in to comment.