Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ The released versions correspond to PyPI releases.
the real filesystem behavior
* remove support for Python versions before 3.10 (if needed, patches may be backported to the 5.x branch)

## Unreleased

### Infrastructure
* fixed some warnings in tests (see [#1190](../../issues/1190))

## [Version 5.9.1](https://pypi.python.org/pypi/pyfakefs/5.9.1) (2025-06-23)
Fixes regression in packaging in version 5.9.0.

Expand Down
3 changes: 2 additions & 1 deletion pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@ def _find_modules(self) -> None:
modules.
"""
module_names = list(self._fake_module_classes.keys()) + [PATH_MODULE]
for name, module in list(sys.modules.items()):
items = sys.modules.copy().items()
for name, module in items:
try:
if (
self.use_cache
Expand Down
4 changes: 3 additions & 1 deletion pyfakefs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ def __init__(
errors: str = "strict",
):
self._bytestream = io.BytesIO(contents or b"")
super().__init__(self._bytestream, encoding, errors, newline)
super().__init__(
self._bytestream, encoding=encoding, errors=errors, newline=newline
)

def getvalue(self) -> bytes:
return self._bytestream.getvalue()
Expand Down
2 changes: 1 addition & 1 deletion pyfakefs/tests/fake_filesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,7 @@ def create_symlinks(self, symlinks):
def _setup_temp_directory():
real_directory = tempfile.mkdtemp()
os.mkdir(os.path.join(real_directory, "fixtures"))
with open(os.path.join(real_directory, "all_tests.py"), "w"):
with open(os.path.join(real_directory, "all_tests.py"), "w", encoding="utf8"):
pass
return real_directory

Expand Down
16 changes: 14 additions & 2 deletions pyfakefs/tests/fake_filesystem_unittest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ def test_pause_resume(self):
self.resume()
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))
self.pause()
real_temp_file.close()
self.resume()

def test_pause_resume_fs(self):
fake_temp_file = tempfile.NamedTemporaryFile()
Expand All @@ -607,6 +610,9 @@ def test_pause_resume_fs(self):
self.fs.resume()
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))
self.fs.pause()
real_temp_file.close()
self.fs.resume()

def test_pause_resume_contextmanager(self):
fake_temp_file = tempfile.NamedTemporaryFile()
Expand All @@ -618,6 +624,7 @@ def test_pause_resume_contextmanager(self):
real_temp_file = tempfile.NamedTemporaryFile()
self.assertFalse(self.fs.exists(real_temp_file.name))
self.assertTrue(os.path.exists(real_temp_file.name))
real_temp_file.close()
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))

Expand All @@ -631,6 +638,7 @@ def test_pause_resume_fs_contextmanager(self):
real_temp_file = tempfile.NamedTemporaryFile()
self.assertFalse(self.fs.exists(real_temp_file.name))
self.assertTrue(os.path.exists(real_temp_file.name))
real_temp_file.close()
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))

Expand Down Expand Up @@ -662,7 +670,10 @@ def test_pause_resume(self):
p.resume()
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))
real_temp_file.close()
fake_temp_file.close()
p.pause()
real_temp_file.close()
p.resume()

def test_pause_resume_contextmanager(self):
with Patcher() as p:
Expand All @@ -675,9 +686,10 @@ def test_pause_resume_contextmanager(self):
real_temp_file = tempfile.NamedTemporaryFile()
self.assertFalse(p.fs.exists(real_temp_file.name))
self.assertTrue(os.path.exists(real_temp_file.name))
real_temp_file.close()
self.assertFalse(os.path.exists(real_temp_file.name))
self.assertTrue(os.path.exists(fake_temp_file.name))
real_temp_file.close()
fake_temp_file.close()


class TestPyfakefsTestCase(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions pyfakefs/tests/fake_filesystem_vs_real_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ def test_directory_permissions(self):
self.fake_os.chmod(fake_path, mode)

try:
self.assertFileHandleOpenBehaviorsMatch("a/write", "w")
self.assertFileHandleOpenBehaviorsMatch("b/write", "w")
self.assertFileHandleOpenBehaviorsMatch("a/write", "w", encoding="utf8")
self.assertFileHandleOpenBehaviorsMatch("b/write", "w", encoding="utf8")
self.assertAllOsBehaviorsMatch("b/stat_dir")
finally:
for path in ["b", "b/stat_dir"]:
Expand Down
4 changes: 2 additions & 2 deletions pyfakefs/tests/fake_open_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1436,11 +1436,11 @@ def test_writing_over_buffer_end(self):
line_end_size = len(self.os.linesep)
char_count = io.DEFAULT_BUFFER_SIZE // 256 - line_end_size
for line_count in (255, 256, 257, 511, 512, 513):
with self.open(file_path, "w") as f:
with self.open(file_path, "w", encoding="utf8") as f:
for i in range(line_count):
f.write("x" * char_count + "\n")

with self.open(file_path) as f:
with self.open(file_path, encoding="utf8") as f:
lines = f.readlines()
self.assertEqual(line_count, len(lines))

Expand Down
6 changes: 3 additions & 3 deletions pyfakefs/tests/skipped_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@


def read_pathlib(file_name):
return (Path(__file__).parent / file_name).open("r").read()
return (Path(__file__).parent / file_name).open("r", encoding="utf8").read()


def read_text_pathlib(file_name):
return (Path(__file__).parent / file_name).read_text()
return (Path(__file__).parent / file_name).read_text(encoding="utf8")


def read_bytes_pathlib(file_name):
Expand All @@ -34,5 +34,5 @@ def check_exists_pathlib():


def read_open(file_name):
with open(os.path.join(os.path.dirname(__file__), file_name)) as f:
with open(os.path.join(os.path.dirname(__file__), file_name), encoding="utf8") as f:
return f.read()
Loading