Skip to content

Commit bee0887

Browse files
committed
Import distutils.file_util to prevent fake fs caching problem
- closes #501
1 parent a6b88e9 commit bee0887

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGES.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ of 2020. As pyfakefs 4.0 is a major release, we are giving you advance notice of
88
the proposed changes so you can be ready.
99

1010
* pyfakefs 4.0 drops support for Python 2.7. If you still need
11-
Python 2.7, you can still use the latest pyfakefs 3.x version.
11+
Python 2.7, you can continue to use the latest pyfakefs 3.x version.
1212

1313
## Version 3.7 (as yet unreleased)
1414

1515
### Fixes
16+
* fixed a problem related to patching `distutils` functions
17+
([#501](../../issues/501))
1618
* correctly handle missing read permission for parent directory
1719
(see [#496](../../issues/496))
1820
* raise for `os.scandir` with non-existing directory

pyfakefs/fake_filesystem_unittest.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import unittest
4444
import warnings
4545
import zipfile # noqa: F401 make sure it gets correctly stubbed, see #427
46+
import distutils.file_util # noqa: F401 same reason - see #501
4647

4748
from pyfakefs.fake_filesystem import set_uid, set_gid, reset_ids
4849

pyfakefs/tests/fake_filesystem_unittest_test.py

+28
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import sys
2626
import tempfile
2727
import unittest
28+
from distutils.dir_util import copy_tree, remove_tree
2829
from unittest import TestCase
2930

3031
from pyfakefs import fake_filesystem_unittest, fake_filesystem
@@ -604,5 +605,32 @@ def test_b(self):
604605
shutil.make_archive('archive', 'zip', root_dir='foo')
605606

606607

608+
class TestDistutilsCopyTree(fake_filesystem_unittest.TestCase):
609+
"""Regression test for #501."""
610+
611+
def setUp(self):
612+
self.setUpPyfakefs()
613+
self.fs.create_dir("./test/subdir/")
614+
self.fs.create_dir("./test/subdir2/")
615+
self.fs.create_file("./test2/subdir/1.txt")
616+
617+
def test_file_copied(self):
618+
copy_tree("./test2/", "./test/")
619+
remove_tree("./test2/")
620+
621+
self.assertTrue(os.path.isfile('./test/subdir/1.txt'))
622+
self.assertFalse(os.path.isdir('./test2/'))
623+
624+
def test_file_copied_again(self):
625+
# used to fail because 'test2' could not be found
626+
self.assertTrue(os.path.isfile('./test2/subdir/1.txt'))
627+
628+
copy_tree("./test2/", "./test/")
629+
remove_tree("./test2/")
630+
631+
self.assertTrue(os.path.isfile('./test/subdir/1.txt'))
632+
self.assertFalse(os.path.isdir('./test2/'))
633+
634+
607635
if __name__ == "__main__":
608636
unittest.main()

0 commit comments

Comments
 (0)