Skip to content

Commit 567480c

Browse files
committed
Add patching getcwd/getcwdb for nt
- fixes Windows problem if called from fspath, if the real current drive is not C: - fixes test for #892 under Windows
1 parent 4e99991 commit 567480c

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGES.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ The released versions correspond to PyPI releases.
1111
* make sure tests work without HOME environment set (see [#870](../../issues/870))
1212
* automount drive or UNC path under Windows if needed for `pathlib.Path.mkdir()`
1313
(see [#890](../../issues/890))
14-
* adapt patching `io.open` to work with Python 3.12 (see [#836](../../issues/836))
14+
* adapt patching `io.open` and `io.open_code` to work with Python 3.12
15+
(see [#836](../../issues/836) and [#892](../../issues/892))
1516

1617
## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-08-18)
1718
Fixes a rare problem on pytest shutdown.
1819

1920
### Fixes
2021
* Clear the patched module cache on session shutdown (pytest only)
21-
(see [#866](../../issues/866)). Added a class method `Patcher.cler_fs_cache`
22+
(see [#866](../../issues/866)). Added a class method `Patcher.clear_fs_cache`
2223
for clearing the patched module cache.
2324

2425
## [Version 5.2.3](https://pypi.python.org/pypi/pyfakefs/5.2.3) (2023-07-10)

pyfakefs/fake_path.py

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
make_string_path,
4040
to_string,
4141
matching_string,
42+
to_bytes,
4243
)
4344

4445
if TYPE_CHECKING:
@@ -507,6 +508,14 @@ def __init__(self, filesystem: "FakeFilesystem"):
507508
self.filesystem = filesystem
508509
self.nt_module: Any = nt
509510

511+
def getcwd(self) -> str:
512+
"""Return current working directory."""
513+
return to_string(self.filesystem.cwd)
514+
515+
def getcwdb(self) -> bytes:
516+
"""Return current working directory as bytes."""
517+
return to_bytes(self.filesystem.cwd)
518+
510519
if sys.version_info >= (3, 12):
511520

512521
def _path_isdir(self, path: AnyStr) -> bool:

pyfakefs/tests/fake_filesystem_unittest_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ def import_foo(self):
805805
mod = importlib.util.module_from_spec(spec)
806806
spec.loader.exec_module(mod)
807807

808-
@unittest.skipIf(sys.platform == "win32", "Not yet working under Windows")
809808
def test_exec_module_in_fake_fs(self):
810809
self.fs.create_file("/foo/bar.py", contents="print('hello')")
811810
with redirect_stdout(StringIO()) as stdout:

0 commit comments

Comments
 (0)