-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using sys.modules to patch all modules seems insufficient #199
Comments
You are not doing anything wrong. This is indeed a shortcoming with pyfakefs and dynamic imports, and I have seen the same problem with Django views if using urlpatterns = patterns(
'config.views',
url(r'^configuration/$', 'config_page'),
... use from . import views
urlpatterns = [
url(r'^configuration/$', views.config_page),
... you have to import the view class there and the problem may go away. Note that I have not tested this, though. If this does not help (or you already use that syntax), you can import the view class in your test source - this works, but gives an "unused import" warning. |
@SebastianFree - any progress on that? Do you need more help? |
Hi, |
@SebastianFree - if you are still at this, can you please check if the problem persists with the current master branch? I added a fix for this, but I'm not completely sue that this resolves the problem. |
I could reproduce the problem in Django code, and it's now fixed for me. Closing this, please reopen if it doesn't work for you. |
I am using PyFakeFS (newest version) with its unit test implementation in a Django environment and Python 3.5.
Looking at the
Patcher
class, it seems insufficient to iterate oversys.modules.items()
since it returns only those modules that have been imported until that point.If my unit test imports a new module after
self.setUpPyfakefs()
, 'os' for example will not be patched there.I managed to patch a new module using this wild construct:
self._stubber._stubs.SmartSet(new_module, 'os', self._stubber.fake_os)
but only after importing it, of course.What am I doing wrong? How can modules that are being imported after setup still be patched automatically?
Thank you
The text was updated successfully, but these errors were encountered: