Skip to content

Commit

Permalink
Remove workaround for patching "open" in Python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Sep 7, 2023
1 parent 79f4a52 commit b088b8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
6 changes: 0 additions & 6 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
to `:py:class`pyfakefs.fake_filesystem_unittest.TestCase`.
"""
import _io # type:ignore[import]
import builtins
import doctest
import functools
import genericpath
Expand Down Expand Up @@ -560,7 +559,6 @@ def __init__(
# save the original open function for use in pytest plugin
self.original_open = open
self.patch_open_code = patch_open_code
self.fake_open: fake_open.FakeFileOpen

if additional_skip_names is not None:
skip_names = [
Expand Down Expand Up @@ -851,7 +849,6 @@ def _refresh(self) -> None:

self.fs = fake_filesystem.FakeFilesystem(patcher=self, create_temp_dir=True)
self.fs.patch_open_code = self.patch_open_code
self.fake_open = fake_open.FakeFileOpen(self.fs)
for name in self._fake_module_classes:
self.fake_modules[name] = self._fake_module_classes[name](self.fs)
if hasattr(self.fake_modules[name], "skip_names"):
Expand Down Expand Up @@ -930,9 +927,6 @@ def patch_modules(self) -> None:
for module, attr in modules:
if attr in self.unfaked_modules:
self._stubs.smart_set(module, name, self.unfaked_modules[attr])
if sys.version_info >= (3, 12):
# workaround for patching open - does not work with skip modules
self._stubs.smart_set(builtins, "open", self.fake_open)

def patch_defaults(self) -> None:
for fct, idx, ft in self.FS_DEFARGS:
Expand Down
18 changes: 8 additions & 10 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,12 @@ def test_import_function_from_os_as_other_name(self):
stat_result = pyfakefs.tests.import_as_example.file_stat2(file_path)
self.assertEqual(3, stat_result.st_size)

@unittest.skipIf(sys.version_info >= (3, 12), "Currently not working in 3.12")
def test_import_open_as_other_name(self):
file_path = "/foo/bar"
self.fs.create_file(file_path, contents=b"abc")
contents = pyfakefs.tests.import_as_example.file_contents1(file_path)
self.assertEqual("abc", contents)

@unittest.skipIf(sys.version_info >= (3, 12), "Currently not working in 3.12")
def test_import_io_open_as_other_name(self):
file_path = "/foo/bar"
self.fs.create_file(file_path, contents=b"abc")
Expand Down Expand Up @@ -398,10 +396,10 @@ def test_fake_path_does_not_exist7(self):
self.fs.create_file("foo")
self.assertFalse(pyfakefs.tests.import_as_example.check_if_exists7("foo"))

@unittest.skipIf(
sys.version_info >= (3, 12),
"Skip modules currently not working for open in 3.12",
)
# @unittest.skipIf(
# sys.version_info >= (3, 12),
# "Skip modules currently not working for open in 3.12",
# )
def test_open_succeeds(self):
pyfakefs.tests.import_as_example.open_this_file()

Expand Down Expand Up @@ -447,10 +445,10 @@ def test_fake_path_does_not_exist7(self):
self.fs.create_file("foo")
self.assertFalse(pyfakefs.tests.import_as_example.check_if_exists7("foo"))

@unittest.skipIf(
sys.version_info >= (3, 12),
"Skip modules currently not working for open in 3.12",
)
# @unittest.skipIf(
# sys.version_info >= (3, 12),
# "Skip modules currently not working for open in 3.12",
# )
def test_open_succeeds(self):
pyfakefs.tests.import_as_example.open_this_file()

Expand Down

0 comments on commit b088b8e

Please sign in to comment.