Skip to content

Commit

Permalink
Find additional modules in setup to find modules imported after __init__
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbean-bremen committed Aug 7, 2017
1 parent 639c66c commit 874f023
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions pyfakefs/fake_filesystem_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ def __init__(self, additional_skip_names=None, patch_path=True):
self._skipNames.discard('genericpath')

# Attributes set by _findModules()
self._os_modules = None
self._path_modules = None
self._os_modules = set()
self._path_modules = set()
if self.HAS_PATHLIB:
self._pathlib_modules = None
self._shutil_modules = None
self._io_modules = None
self._pathlib_modules = set()
self._shutil_modules = set()
self._io_modules = set()
self._findModules()
assert None not in vars(self).values(), \
"_findModules() missed the initialization of an instance variable"
Expand All @@ -278,12 +278,9 @@ def __init__(self, additional_skip_names=None, patch_path=True):
self.fake_shutil = None
self.fake_open = None
self.fake_io = None

# _isStale is set by tearDown(), reset by _refresh()
self._isStale = True
self._refresh()
assert None not in vars(self).values(), \
"_refresh() missed the initialization of an instance variable"
assert self._isStale == False, "_refresh() did not reset _isStale"

def __enter__(self):
"""Context manager for usage outside of fake_filesystem_unittest.TestCase.
Expand All @@ -299,12 +296,6 @@ def _findModules(self):
Later, `setUp()` will stub these with the fake file system
modules.
"""
self._os_modules = set()
self._path_modules = set()
if self.HAS_PATHLIB:
self._pathlib_modules = set()
self._shutil_modules = set()
self._io_modules = set()
for name, module in set(sys.modules.items()):
if (module in self.SKIPMODULES or
(not inspect.ismodule(module)) or
Expand Down Expand Up @@ -347,7 +338,10 @@ def setUp(self, doctester=None):
modules real ones. Also bind the fake `file()` and `open()` functions.
"""
temp_dir = tempfile.gettempdir()
self._findModules()
self._refresh()
assert None not in vars(self).values(), \
"_findModules() missed the initialization of an instance variable"

if doctester is not None:
doctester.globs = self.replaceGlobs(doctester.globs)
Expand Down

0 comments on commit 874f023

Please sign in to comment.