Skip to content

[linux] test_swap_memory fails when swap is fully used #1911

@andir

Description

@andir

Summary

  • OS: Linux, NixOS
  • Architecture: 64bit, 32bit
  • Psutil version: 5.8.0
  • Python version: python 3.8
  • Type: tests

Description

When running the tests on a box that has used 100% of the available swap space and still has plenty of RAM remaining the tests fail as follows:

    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=1048567808, used=1048567808, free=0, percent=100.0, sin=50741248, sout=1316823040)                       
 E           assert 0 > 0
 E            +  where 0 = sswap(total=1048567808, used=1048567808, free=0, percent=100.0, sin=50741248, sout=1316823040).free    

I have no idea how to fix this test. It seems like it reads out the data correctly but what is the expectation? You can't expect swap to be fully unused. It might be fully used for stuff that isn't currently needed.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions