Skip to content

Commit

Permalink
print more sys info on test start
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jan 1, 2024
1 parent 3cabd5e commit 450bc00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
30 changes: 21 additions & 9 deletions psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions psutil/tests/test_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = []
Expand Down

0 comments on commit 450bc00

Please sign in to comment.