psutil icon indicating copy to clipboard operation
psutil copied to clipboard

[Linux] test_swap_memory fails when swap is at 100% usage

Open AlexandreTunstall opened this issue 11 months ago • 0 comments

Summary

  • OS: Linux
  • Architecture: amd64
  • Psutil version: 5.9.5
  • Python version: 3.10.12
  • Type: tests

Description

The test appears to assert that free swap is non-zero when total swap is non-zero. When all swap is in use, this causes the test to fail.

============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.2.1, pluggy-1.0.0
rootdir: /nix/store/f43p2hab6y6hqqmlnyp6c61cx2kslifx-python3.10-psutil-5.9.5/lib/python3.10/site-packages/psutil/tests
collected 44 items / 16 deselected / 28 selected                               

../../nix/store/f43p2hab6y6hqqmlnyp6c61cx2kslifx-python3.10-psutil-5.9.5/lib/python3.10/site-packages/psutil/tests/test_system.py . [  3%]
........F..........s.......                                              [100%]

=================================== FAILURES ===================================
_______________________ TestMemoryAPIs.test_swap_memory ________________________

self = <psutil.tests.test_system.TestMemoryAPIs testMethod=test_swap_memory>

    def test_swap_memory(self):
        mem = psutil.swap_memory()
        self.assertEqual(
            mem._fields, ('total', 'used', 'free', 'percent', 'sin', 'sout'))
    
        assert mem.total >= 0, mem
        assert mem.used >= 0, mem
        if mem.total > 0:
            # likely a system with no swap partition
>           assert mem.free > 0, mem
E           AssertionError: sswap(total=8204054528, used=8204054528, free=0, percent=100.0, sin=35428151296, sout=75186987008)
E           assert 0 > 0
E            +  where 0 = sswap(total=8204054528, used=8204054528, free=0, percent=100.0, sin=35428151296, sout=75186987008).free

/nix/store/f43p2hab6y6hqqmlnyp6c61cx2kslifx-python3.10-psutil-5.9.5/lib/python3.10/site-packages/psutil/tests/test_system.py:298: AssertionError
=========================== short test summary info ============================
FAILED ../../nix/store/f43p2hab6y6hqqmlnyp6c61cx2kslifx-python3.10-psutil-5.9.5/lib/python3.10/site-packages/psutil/tests/test_system.py::TestMemoryAPIs::test_swap_memory - AssertionError: sswap(total=8204054528, used=8204054528, free=0, percent=10...
============ 1 failed, 26 passed, 1 skipped, 16 deselected in 0.63s ============

Some swap statistics to show that the swap measurement is correct:

grep /proc/meminfo -e Swap
SwapCached:       138628 kB
SwapTotal:       8011772 kB
SwapFree:              0 kB

AlexandreTunstall avatar Jul 30 '23 03:07 AlexandreTunstall