From 450bc00163414d568b23c6d580701baf6e14c263 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Mon, 1 Jan 2024 13:25:31 +0100 Subject: [PATCH] print more sys info on test start --- psutil/tests/__init__.py | 30 +++++++++++++++++++++--------- psutil/tests/test_linux.py | 9 ++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/psutil/tests/__init__.py b/psutil/tests/__init__.py index f28e13bc4..f5c9fbe5d 100644 --- a/psutil/tests/__init__.py +++ b/psutil/tests/__init__.py @@ -1222,6 +1222,15 @@ def print_sysinfo(): except ImportError: wheel = None + def print_section(section, info): + print("\n" + " {} ".format(section).center(70, "=") + "\n", # NOQA + file=sys.stderr) + if isinstance(info, str): + print(info, file=sys.stderr) # NOQA + else: + pprint.pprint(info) # NOQA + sys.stdout.flush() + info = collections.OrderedDict() # OS @@ -1288,18 +1297,21 @@ def print_sysinfo(): info['pids'] = len(psutil.pids()) pinfo = psutil.Process().as_dict() pinfo.pop('memory_maps', None) - info['proc'] = pprint.pformat(pinfo) + info['proc'] = pinfo + info['partitions'] = psutil.disk_partitions(all=True) - print("=" * 70, file=sys.stderr) # NOQA - for k, v in info.items(): - print("%-17s %s" % (k + ':', v), file=sys.stderr) # NOQA - print("=" * 70, file=sys.stderr) # NOQA - sys.stdout.flush() + print_section("psutil", info) + + if POSIX and which("mount"): + print_section("mount", sh("mount")) if WINDOWS: - os.system("tasklist") + print_section( + "tasklist", subprocess.check_output(["tasklist"], text=True)) elif which("ps"): - os.system("ps aux") + print_section( + "ps aux", subprocess.check_output(["ps", "aux"], text=True)) + print("=" * 70, file=sys.stderr) # NOQA sys.stdout.flush() @@ -1585,7 +1597,7 @@ def wrapper(*args, **kwargs): if not only_if: raise msg = "%r was skipped because it raised NotImplementedError" \ - % fun.__name__ + % fun.__name__ raise unittest.SkipTest(msg) return wrapper return decorator diff --git a/psutil/tests/test_linux.py b/psutil/tests/test_linux.py index c640953bf..15d267845 100755 --- a/psutil/tests/test_linux.py +++ b/psutil/tests/test_linux.py @@ -1119,9 +1119,7 @@ def test_emulate_unix(self): @unittest.skipIf(not LINUX, "LINUX only") -class TestSystemDiskPartitions(PsutilTestCase): - maxDiff = None - +class TestSystemDiskUsage(PsutilTestCase): @unittest.skipIf(not hasattr(os, 'statvfs'), "os.statvfs() not available") @skip_on_not_implemented() def test_against_df(self): @@ -1147,6 +1145,11 @@ def df(path): self.assertAlmostEqual(usage.used, used, delta=TOLERANCE_DISK_USAGE) + +@unittest.skipIf(not LINUX, "LINUX only") +class TestSystemDiskPartitions(PsutilTestCase): + maxDiff = None + def test_against_mount(self): def parse_mount(out): ls = []