Skip to content
Advertisement

Tag: python-module

Mock an entire module in python

I have an application that imports a module from PyPI. I want to write unittests for that application’s source code, but I do not want to use the module from PyPI in those tests. I want to mock it entirely (the testing machine will not contain that PyPI module, so any import will fail). Currently, each time I try to

Why can’t a module be a context manager (to a ‘with’ statement)?

Suppose we have the following mod.py: and the following use of it: I get an error: According to the documentation the documentation the with statement should execute as follows (I believe it fails at step 2 and therefore truncate the list): The context expression (the expression given in the with_item) is evaluated to obtain a context manager. The context manager’s

Unable to import a module that is definitely installed

After installing mechanize, I don’t seem to be able to import it. I have tried installing from pip, easy_install, and via python setup.py install from this repo: https://github.com/abielr/mechanize. All of this to no avail, as each time I enter my Python interactive I get: The installations I ran previously reported that they had completed successfully, so I expect the import

Advertisement