diff --git a/.github/workflows/testsuite.yml b/.github/workflows/testsuite.yml index be90065e..840f4526 100644 --- a/.github/workflows/testsuite.yml +++ b/.github/workflows/testsuite.yml @@ -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 diff --git a/CHANGES.md b/CHANGES.md index cac49c56..3aa409eb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/pyfakefs/fake_filesystem_unittest.py b/pyfakefs/fake_filesystem_unittest.py index c6495e0c..271791d5 100644 --- a/pyfakefs/fake_filesystem_unittest.py +++ b/pyfakefs/fake_filesystem_unittest.py @@ -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] diff --git a/pyfakefs/pytest_tests/pytest_fixture_test.py b/pyfakefs/pytest_tests/pytest_fixture_test.py index 27ea9081..2b158980 100644 --- a/pyfakefs/pytest_tests/pytest_fixture_test.py +++ b/pyfakefs/pytest_tests/pytest_fixture_test.py @@ -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 @@ -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"