Skip to content

filelock_test does not catch faulty lock #220

@TheMatt2

Description

@TheMatt2

There is a potential issue in test_filelock.py

If someone where to introduce a bug (such as reintroducing #31) that caused file locking
not to secure exclusive access, no test actually fails. Instead, a warning is shown by Pytest:

(do to the nature of this kind of bug, it seems sometimes this would succeed with no warning at all)

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

========================================================================= warnings summary ==========================================================================
tests/test_filelock.py::test_threaded_lock_different_lock_obj[UnixFileLock]
  .../site-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread t2_8
  
  Traceback (most recent call last):
    File ".../threading.py", line 1038, in _bootstrap_inner
      self.run()
    File "py-filelock/tests/test_filelock.py", line 187, in run
      super().run()
    File ".../threading.py", line 975, in run
      self._target(*self._args, **self._kwargs)
    File "py-filelock/tests/test_filelock.py", line 234, in t_2
      assert not lock_1.is_locked
  AssertionError: assert not True
   +  where True = <filelock._unix.UnixFileLock object at 0x1030ef3d0>.is_locked
  
    warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================== 50 passed, 1 warning in 3.53s ===================================================================

Results found by adding the follow to py-filelock/src/filelock/_unix.py > UnixFileLock > _release

59            try:
60                os.remove(self._lock_file)
61            except OSError:
62                pass

The issue seems to be that the test test_filelock.py::test_threaded_lock_different_lock_obj[UnixFileLock] is failing with a AssertionError exception. However, only RuntimeError's are caught in threads created during the testing process.

https://github.com/tox-dev/py-filelock/blob/b815134c9bc62aecbe2d8b85a875690d55df5667/tests/test_filelock.py#L185-L189

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