From 0de8b72fce727d8a2e102e642e3aba6d2312d249 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Sun, 3 Nov 2024 21:26:50 +0100 Subject: [PATCH] Fix KeyError in MountPoint.__repr__() if mount does not exist --- test/test_modules.py | 2 ++ testinfra/modules/mountpoint.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/test_modules.py b/test/test_modules.py index 15416344..c4bc91a0 100644 --- a/test/test_modules.py +++ b/test/test_modules.py @@ -482,12 +482,14 @@ def test_supervisor(host, supervisorctl_path, supervisorctl_conf): def test_mountpoint(host): root_mount = host.mount_point("/") assert root_mount.exists + assert repr(root_mount) assert isinstance(root_mount.options, list) assert "rw" in root_mount.options assert root_mount.filesystem fake_mount = host.mount_point("/fake/mount") assert not fake_mount.exists + assert repr(fake_mount) mountpoints = host.mount_point.get_mountpoints() assert mountpoints diff --git a/testinfra/modules/mountpoint.py b/testinfra/modules/mountpoint.py index 4fd5369e..3757ca6f 100644 --- a/testinfra/modules/mountpoint.py +++ b/testinfra/modules/mountpoint.py @@ -101,13 +101,17 @@ def get_module_class(cls, host): raise NotImplementedError def __repr__(self): + if self.exists: + d = self.device + f = self.filesystem + o = ",".join(self.options) + else: + d = "" + f = "" + o = "" return ( - "" - ).format( - self.path, - self.device, - self.filesystem, - ",".join(self.options), + f'' )