Skip to content

Commit

Permalink
Use a separate fake module for _io
Browse files Browse the repository at this point in the history
- in Python 3.12, _io is not a simple alias for io
- fixes pytest-dev#910
  • Loading branch information
mrbean-bremen committed Nov 19, 2023
1 parent 8c7a99c commit 01b081e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ jobs:
fi
shell: bash
- name: Install extra dependencies
if: ${{ matrix.python-version != '3.12-dev' && matrix.python-version != 'pypy-3.10' }}
if: ${{ matrix.python-version != 'pypy-3.10' }}
run: |
pip install -r extra_requirements.txt
pip install zstandard cffi # needed to test #910
shell: bash
- name: Run unit tests with extra packages as non-root user
if: ${{ matrix.python-version != '3.12-dev' && matrix.python-version != 'pypy-3.10' }}
if: ${{ matrix.python-version != 'pypy-3.10' }}
run: |
export PYTHON_ZSTANDARD_IMPORT_POLICY=cffi # needed to test #910
python -m pyfakefs.tests.all_tests
shell: bash
- name: Run performance tests
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
* fixed a problem with patching `_io` under Python 3.12 (see [#910](../../issues/910))

## [Version 5.3.1](https://pypi.python.org/pypi/pyfakefs/5.3.0) (2023-11-15)
Mostly a bugfix release.

Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def _init_fake_module_classes(self) -> None:
}
if IS_PYPY or sys.version_info >= (3, 12):
# in PyPy and later cpython versions, the module is referenced as _io
self._fake_module_classes["_io"] = fake_io.FakeIoModule
self._fake_module_classes["_io"] = fake_io.FakeIoModule2
if sys.platform == "win32":
self._fake_module_classes["nt"] = fake_path.FakeNtModule
else:
Expand Down
13 changes: 13 additions & 0 deletions pyfakefs/fake_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
""" Uses :py:class:`FakeIoModule` to provide a
fake ``io`` module replacement.
"""
import _io # pytype: disable=import-error
import io
import os
import sys
Expand Down Expand Up @@ -150,6 +151,18 @@ def __getattr__(self, name):
return getattr(self._io_module, name)


class FakeIoModule2(FakeIoModule):
"""Similar to ``FakeIoModule``, but fakes `_io` instead of `io`."""

def __init__(self, filesystem: "FakeFilesystem"):
"""
Args:
filesystem: FakeFilesystem used to provide file system information.
"""
super().__init__(filesystem)
self._io_module = _io


if sys.platform != "win32":
import fcntl

Expand Down

0 comments on commit 01b081e

Please sign in to comment.