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

TypeError: unhashable type #923

Closed
trulave opened this issue Dec 13, 2023 · 1 comment · Fixed by #924
Closed

TypeError: unhashable type #923

trulave opened this issue Dec 13, 2023 · 1 comment · Fixed by #924
Labels

Comments

@trulave
Copy link

trulave commented Dec 13, 2023

Describe the bug
Call setUp fails on fake_filesystem_unittest.py::_find_modules when one of the modules has unhashable type. I don't know wether is a bad (Undefined) module or not, but I think this is weird behavior.

self = <pyfakefs.fake_filesystem_unittest.Patcher object at 0x7fdc28337d50>

    def _find_modules(self) -> None:
        """Find and cache all modules that import file system modules.
        Later, `setUp()` will stub these with the fake file system
        modules.
        """
        module_names = list(self._fake_module_classes.keys()) + [PATH_MODULE]
        for name, module in list(sys.modules.items()):
            try:
                if (
                    self.use_cache
                    and module in self.CACHED_MODULES
                    or not inspect.ismodule(module)
                ):
                    continue
            except Exception:
                # workaround for some py (part of pytest) versions
                # where py.error has no __name__ attribute
                # 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)
E                   TypeError: unhashable type: 'Undefined'

List of unhashable modules:

>>> [i for i in sys.modules.items() if not isinstance(i[1], typing.Hashable)]
[('undefined', Undefined)]

How To Reproduce

  1. Install suspicious unhashable module such as Undefined
  2. Run tests which uses pyfakefs

Environment

Linux-6.2.0-37-generic-x86_64-with-glibc2.35
Python 3.11.7 (main, Dec  8 2023, 18:56:58) [GCC 11.4.0]
pyfakefs 5.3.2
pytest 7.4.3
@mrbean-bremen
Copy link
Member

Thanks, good catch! I hadn't thought about this possibility... I have to think what to do in this case... maybe just ignore the module.

mrbean-bremen added a commit to mrbean-bremen/pyfakefs that referenced this issue Dec 14, 2023
- caused exception while scanning modules
- fixes pytest-dev#923
mrbean-bremen added a commit that referenced this issue Dec 17, 2023
- caused exception while scanning modules
- fixes #923
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants