Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError in MountPoint.__repr__() #781

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

CarstenGrohmann
Copy link
Contributor

@CarstenGrohmann CarstenGrohmann commented Oct 30, 2024

MountPoint.__repr__() triggered a KeyError exception if the mount point doesn't exist. The commit below fixes this problem.

Solved error:

__________________ test_mountpoint[docker://debian_bookworm] ___________________
[gw1] linux -- Python 3.9.20 /home/runner/work/pytest-testinfra/pytest-testinfra/.tox/py39/bin/python

host = <testinfra.host.Host docker://debian_bookworm>

    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)

test/test_modules.py:492: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
testinfra/modules/mountpoint.py:108: in __repr__
    self.device,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <[KeyError('device') raised in repr()] LinuxMountPoint object at 0x7fa72d956b80>

    @property
    def device(self):
        """Return the device associated
    
        >>> host.mount_point("/").device
        '/dev/sda1'
    
        """
>       return self._attrs["device"]
E       KeyError: 'device'

testinfra/modules/mountpoint.py:70: KeyError

@CarstenGrohmann CarstenGrohmann force-pushed the fix_keyerror_in_MountPoint__repr__ branch from 2c84f7d to da7c5aa Compare November 3, 2024 20:36
@CarstenGrohmann CarstenGrohmann changed the title DRAFT: Add test for MountPoint.__repr__() Add test for MountPoint.__repr__() Nov 3, 2024
@CarstenGrohmann CarstenGrohmann force-pushed the fix_keyerror_in_MountPoint__repr__ branch from da7c5aa to 0de8b72 Compare November 3, 2024 20:42
@CarstenGrohmann CarstenGrohmann changed the title Add test for MountPoint.__repr__() Fix KeyError in MountPoint.__repr__() Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant