Skip to content

Commit

Permalink
Handle unhashable modules
Browse files Browse the repository at this point in the history
- caused exception while scanning modules
- fixes #923
  • Loading branch information
mrbean-bremen committed Dec 17, 2023
1 parent d17e190 commit 1ad9158
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
run: |
pip install -r requirements.txt
pip install -U pytest==${{ matrix.pytest-version }}
pip install opentimelineio
pip install opentimelineio undefined
pip install -e .
if [[ '${{ matrix.pytest-version }}' == '4.0.2' ]]; then
pip install -U attrs==19.1.0
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# pyfakefs Release Notes
The released versions correspond to PyPI releases.

## Unreleased

### Fixes
* fixes handling of unhashable modules which cannot be cached (see [#923](../../issues/923))

## [Version 5.3.2](https://pypi.python.org/pypi/pyfakefs/5.3.2) (2023-11-30)
Bugfix release.

Expand Down
6 changes: 5 additions & 1 deletion pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,11 @@ def _find_modules(self) -> None:
# see https://github.com/pytest-dev/py/issues/73
# and any other exception triggered by inspect.ismodule
if self.use_cache:
self.__class__.CACHED_MODULES.add(module)
try:
self.__class__.CACHED_MODULES.add(module)
except TypeError:
# unhashable module - don't cache it
pass
continue
skipped = module in self.SKIPMODULES or any(
[sn.startswith(module.__name__) for sn in self._skip_names]
Expand Down
7 changes: 7 additions & 0 deletions pyfakefs/pytest_tests/pytest_fixture_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Example for a test using a custom pytest fixture with an argument to Patcher

import pytest
import undefined

import pyfakefs.pytest_tests.example as example
from pyfakefs.fake_filesystem_unittest import Patcher
Expand Down Expand Up @@ -41,6 +42,12 @@ def test_example_file_passing_using_patcher():
check_that_example_file_is_in_fake_fs()


def test_undefined(fs):
# regression test for #923
with pytest.raises(NotImplementedError):
print(undefined)


def check_that_example_file_is_in_fake_fs():
with open(example.EXAMPLE_FILE) as file:
assert file.read() == "stuff here"
Expand Down

0 comments on commit 1ad9158

Please sign in to comment.