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

filelock_test does not catch faulty lock #220

Closed
TheMatt2 opened this issue Apr 5, 2023 · 0 comments
Closed

filelock_test does not catch faulty lock #220

TheMatt2 opened this issue Apr 5, 2023 · 0 comments

Comments

@TheMatt2
Copy link
Contributor

TheMatt2 commented Apr 5, 2023

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

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

No branches or pull requests

1 participant