def setUp(self):
self._win32com_mock = mock.MagicMock()
self._module_patcher = mock.patch.dict('sys.modules', {'win32com': self._win32com_mock}
self._module_patcher.start()
module_name = importlib.import_module('<path to module>')
def tearDown(self):
self._module_patcher.stop()--
Thank you,Robert Tingirica
You received this message because you are subscribed to the Google Groups "nose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nose-users+...@googlegroups.com.
To post to this group, send email to nose-...@googlegroups.com.
Visit this group at http://groups.google.com/group/nose-users.
For more options, visit https://groups.google.com/d/optout.
Hello Ned,
Thank you for replying. The module that imports the said non-existing module, is the one that I import using "importlib", the one with the code that I have to test, not a test file. I cannot use mock it there.
It looks something like this:
<module that needs testing> imports <win32com>
<test module that has the mocking i posted> imports <module that needs testing>
sys.modules needs to be patched and not win32com directly, since it does not exist on Linux.
On 9/16/14 7:43 AM, robert tingirica wrote:
Hello Ned,
Thank you for replying. The module that imports the said non-existing module, is the one that I import using "importlib", the one with the code that I have to test, not a test file. I cannot use mock it there.
It looks something like this:
<module that needs testing> imports <win32com>
<test module that has the mocking i posted> imports <module that needs testing>
sys.modules needs to be patched and not win32com directly, since it does not exist on Linux.
I see. Can you show how you're running coverage? I find it best to run nose under coverage rather than to use the nose-cover plugin:
$ coverage run nosetests.py ....
--Ned.
(BTW: top-posting makes it harder to follow the conversation, interleaved style is best.)
I also have the same problem: coverage doesn't show code run through importlib.import_module as covered: we have a factory class that uses reflection to instantiate classes. Tried both "coverage run --timid" and "nosetests --with-coverage".