Skip to content

Test test_filelock.py::test_lock_mode_soft fails if default umask is 002 #223

@TheMatt2

Description

@TheMatt2

Description

Test cases for filelock fail if the umask of the current user is not 022.
This is a problem, because it seems the default umask for Ubuntu 22.10 seems to be 002.

I can see documentation showing it should be 002. I know this is odd, as I was expecting it to be 002.

From /etc/login.defs

#
# Enable setting of the umask group bits to be the same as owner bits
# (examples: 022 -> 002, 077 -> 007) for non-root users, if the uid is
# the same as gid, and username is the same as the primary group name.
#
# If set to yes, userdel will remove the user's group if it contains no
# more members, and useradd will create by default a group with the name
# of the user.
#
USERGROUPS_ENAB yes

This leads to the error in testing:

python3 -m pytest
====================================================== test session starts =======================================================
platform linux -- Python 3.10.7, pytest-7.2.2, pluggy-1.0.0
rootdir: .../py-filelock
plugins: cov-4.0.0, timeout-2.1.0, mock-3.10.0
collected 50 items                                                                                                               

tests/test_error.py ....                                                                                                   [  8%]
tests/test_filelock.py ........................................F.....                                                      [100%]

============================================================ FAILURES ============================================================
______________________________________________________ test_lock_mode_soft _______________________________________________________

tmp_path = PosixPath('.../pytest-4/test_lock_mode_soft0')

    def test_lock_mode_soft(tmp_path: Path) -> None:
        lock_path = tmp_path / "a.lock"
        lock = SoftFileLock(str(lock_path), mode=0o666)
    
        lock.acquire()
        assert lock.is_locked
    
        mode = filemode(os.stat(lock_path).st_mode)
        if sys.platform == "win32":
            assert mode == "-rw-rw-rw-"
        else:
>           assert mode == "-rw-r--r--"
E           AssertionError: assert '-rw-rw-r--' == '-rw-r--r--'
E             - -rw-r--r--
E             + -rw-rw-r--

tests/test_filelock.py:447: AssertionError
==================================================== short test summary info =====================================================
FAILED tests/test_filelock.py::test_lock_mode_soft - AssertionError: assert '-rw-rw-r--' == '-rw-r--r--'
================================================== 1 failed, 49 passed in 1.65s ==================================================

Steps to Reproduce

  1. Set umask umask 002
  2. Run pytest against repo
  3. Observe errrors

Expected behavior

Test cases should either skip or force the umask to make sure everything is working correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions