summaryrefslogtreecommitdiff
path: root/psutil/tests/test_linux.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2021-12-31 12:32:51 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2021-12-31 12:32:51 +0100
commit15cd44a357ca938524e411e519a4d705dabeb08a (patch)
tree45bcf532f8bb442b1c2bd22b9b657ac1578b01c1 /psutil/tests/test_linux.py
parent165be03be67732339ca0b2ed6ac8cf508940fe55 (diff)
downloadpsutil-15cd44a357ca938524e411e519a4d705dabeb08a.tar.gz
avoid spamming debug() messages during tests
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Diffstat (limited to 'psutil/tests/test_linux.py')
-rwxr-xr-xpsutil/tests/test_linux.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py
index 3a71f5d9..1443aab7 100755
--- a/psutil/tests/test_linux.py
+++ b/psutil/tests/test_linux.py
@@ -27,6 +27,7 @@ from psutil import LINUX
from psutil._compat import PY3
from psutil._compat import FileNotFoundError
from psutil._compat import basestring
+from psutil._compat import redirect_stderr
from psutil._compat import u
from psutil.tests import GITHUB_ACTIONS
from psutil.tests import GLOBAL_TIMEOUT
@@ -2262,6 +2263,19 @@ class TestVirtualizationContainers(PsutilTestCase):
def setUp(self):
self.detector = ContainerDetector()
+ self.patch_pydebug()
+
+ def patch_pydebug(self):
+ # Avoid spamming debug messages on screen, still executing the
+ # underlying debug() python code.
+ def debug(msg):
+ with redirect_stderr(io.StringIO()):
+ orig_debug(msg)
+
+ orig_debug = psutil._pslinux.debug
+ m = mock.patch("psutil._pslinux.debug", create=True, side_effect=debug)
+ ctx = m.__enter__()
+ self.addCleanup(ctx.__exit__)
def test_detect_openvz(self):
def exists(path):
@@ -2321,6 +2335,19 @@ class TestVirtualizationVms(PsutilTestCase):
def setUp(self):
self.detector = VmDetector()
+ self.patch_pydebug()
+
+ def patch_pydebug(self):
+ # Avoid spamming debug messages on screen, still executing the
+ # underlying debug() python code.
+ def debug(msg):
+ with redirect_stderr(io.StringIO()):
+ orig_debug(msg)
+
+ orig_debug = psutil._pslinux.debug
+ m = mock.patch("psutil._pslinux.debug", create=True, side_effect=debug)
+ ctx = m.__enter__()
+ self.addCleanup(ctx.__exit__)
def test_ask_dmi(self):
with mock_open_content("/sys/class/dmi/id/sys_vendor", "VMware"):